C++ – Why Use Double Underscore in Syntax

c++syntax

I was taking a look through some open-source C++ code and I noticed a lot of double underscores used within in the code, mainly at the start of variable names.

return __CYGWIN__;

Just wondering: Is there a reason for this, or is it just some people's code styles? I would think that it makes it hard to read.

Best Answer

From Programming in C++, Rules and Recommendations :

The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.

Underscores (`_') are often used in names of library functions (such as "_main" and "_exit"). In order to avoid collisions, do not begin an identifier with an underscore.