tags:

views:

106

answers:

3

The union epoll_data_t looks like:

typedef union epoll_data {  
    void *ptr;  
    int fd;  
    __uint32_t u32;  
    __uint64_t u64;  
} epoll_data_t;

This is more of a general C question, but why are the leading double underscores __uint{32,64} types used instead of just uint{32,64} without the underscores? I don't really understand why/when you would use the underscore version, but I thought that uint32 without underscores would be the proper thing to use in a union publicly modifiable to the outside world.

+1  A: 

Directly from wikipedia [http://en.wikipedia.org/wiki/Underscore]

Many clashes were possible within the external identifier linkage space which potentially mingles code generated by various high level compilers, runtime libraries required by each of these compilers, compiler generated helper functions, and program startup code, of which some fraction was inevitably compiled from system assembly language. Within this collision domain the underscore character quickly became entrenched as the primary mechanism for differentiating the external linkage space. It was common practice for C compilers to prepend a leading underscore to all external scope program identifiers to avert clashes with contributions from runtime language support. Furthermore, when the C/C++ compiler needed to introduce names into external linkage as part of the translation process, these names were often distinguished with some combination of multiple leading or trailing underscores.

Federico
This isn't actually relevant to this particular question though - it's about type names, which don't have linkage in C.
caf
+1  A: 

A leading underscore is reserved to the compiler/library vendor to avoid creating symbols in the global namespace that collide with symbols created by their customers. Unfortunately, customers have been using this too for their own "system level" declarations, as do 3rd party library vendors, forcing the vendors to start using two underscores. Symbols with 3 underscores have been found in the wild but are not yet wide-spread.

Hans Passant
+2  A: 

Fixed-width integer types were standardized with C99. Before that, compiler and library authors introduced their own types, of which these might be a remnant; afaik MS still doesn't ship stdint.h with Visul Studio.

Christoph