I was reading the source code of zmq, and came across the following typedef
typedef struct {unsigned char _ [32];} zmq_msg_t;
I don't understand what the underscore means in this definition. Could someone please help shed some light?
The C gurus have a method to their madness when it comes to naming these variables. The _t stands for something. It's very consistent on purpose. The _t implies a typedef, a defined data type. The typedef is based on an existing type.
The C language contains the typedef keyword to allow users to provide alternative names for the primitive (e.g., int) and user-defined (e.g struct) data types. Remember, this keyword adds a new name for some existing data type but does not create a new type.
The _t usually wraps an opaque type definition. The requirement that additional types defined in this section end in "_t" was prompted by the problem of name space pollution. It is difficult to define a type (where that type is not one defined by POSIX.
Basically struct is used to define a structure. But when we want to use it we have to use the struct keyword in C. If we use the typedef keyword, then a new name, we can use the struct by that name, without writing the struct keyword.
An underscore (_
) is a valid identifier, in this case, a name of the member of the structure. It does not have any special meaning, as such.
Quoting C11
, chapter §6.4.2.1, Identifiers
An identifier is a sequence of nondigit characters (including the underscore
_
, the lowercase and uppercase Latin letters, and other characters) and digits, which designates one or more entities [....]
AFAIR, this is true in case of C++, also, refer chapter 2.11, C++14.
It doesn't mean anything, it's simply the name of the structure member.
It's not the most communicative name, but it's probably chosen to be a bit "secret".
An identifier basically has to match [A-Za-z_][A-Za-z_0-9]*
, and this one does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With