Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the underscore mean in the typedef structure?

Tags:

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?

like image 692
Jerry Feng Avatar asked Feb 16 '17 13:02

Jerry Feng


People also ask

What does the _T mean in C?

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.

What does typedef struct mean?

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.

Why do structs end in _t?

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.

What is the difference between typedef and structure?

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.


2 Answers

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.

like image 139
Sourav Ghosh Avatar answered Oct 06 '22 17:10

Sourav Ghosh


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.

like image 27
unwind Avatar answered Oct 06 '22 17:10

unwind