I recently started learning networking in C and I saw some functions that start with an underscore- like _function()- what does that mean exactly? I also saw this :
struct sockaddr_in {
__SOCKADDR_COMMON (sin_);
in_port_t sin_port;
struct in_addr sin_addr;
unsigned char sin_zero[sizeof (struct sockaddr) -
__SOCKADDR_COMMON_SIZE -
sizeof (in_port_t) -
sizeof (struct in_addr)];
};
what does this parts of the code mean:
__SOCKADDR_COMMON (sin_);
unsigned char sin_zero[sizeof (struct sockaddr) -
__SOCKADDR_COMMON_SIZE -
sizeof (in_port_t) -
sizeof (struct in_addr)];
Best Answer
The underscore prefix is reserved for functions and types used by the compiler and standard library. The standard library can use these names freely because they will never conflict with correct user programs.
The other side to this is that you are not allowed to define names that begin with an underscore.
Well, that is the gist of the rule. The actual rule is this:
You cannot define any identifiers in global scope whose names begin with an underscore, because these may conflict with hidden (private) library definitions. So this is invalid in your code:
But this is valid:
You cannot define any identifiers in any scope whose names begin with two underscores, or one underscore followed by a capital letter. So this is invalid:
But this is okay:
There are actually a few more rules, just to make things complicated, but the ones above are the most often violated and the easiest to remember.