Reputation: 2488
The prelude...
Where I work, people say I have the wrong terminology or invent my own. My boss says the right terminology is very important when working in a team.
The question
In C, what is the right term to use when we are referring to a pointer to any data type? For example I want to create macro functions of a send()
function like this:
size_t send_stub (socket, void* , size_t);
#define send_str(sock, str) send_stub(sock, str, strlen(str))
then it will follow to create such a macro for data types with known size like pointers, byte, int16, int32, int64, arrays, structures, enums, but I would like to create a single macro function for all of them. What would it be called?
#define send_?(sock, ?) send_stub(sock, ?, sizeof(?))
Upvotes: 1
Views: 74
Reputation: 170084
I think we can take our lead from the C standard itself here. I'll be quoting n1570, the C11 standard draft.
3. Terms, definitions, and symbols
3.15 object
1 region of data storage in the execution environment, the contents of which can represent values
2 NOTE When referenced, an object may be interpreted as having a particular type; see 6.3.2.1.
Seems to be right up your alley. If you assume the token provided as argument to the macro is an expression that evaluates to a pointer which points at a single object, then send_object
seems appropriate.
#define send_object(sock, obj_ptr) send_stub(sock, (obj_ptr), sizeof *(obj_ptr))
If we also assume the pointer is to a complete object type, then sizeof *(obj_ptr)
is the size of that object.
Upvotes: 2