Double underscores are reserved to the implementation
The top voted answer cites 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."
However, after reading a few C++ and C standards, I was unable to find any mention of underscores being restricted to just the compiler's internal use. The standards are more general, reserving double underscores for the implementation.
C++
C++ (current working draft, accessed 2019-5-26) states in lex.name
:
- Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use.
- Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
C
Although this question is specific to C++, I've cited relevant sections from C standards 99 and 17:
C99 section 7.1.3
- All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
- All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name
spaces.
C17 says the same thing as C99.
What is the implementation?
For C/C++, the implementation loosely refers to the set resources necessary to produce an executable from user source files. This includes:
- preprocessor
- compiler
- linker
- standard library
Example implementations
There are a number of different C++ implementations mentioned on Wikipedia. (no anchor link, ctrl+f "implementation")
Here's an example of Digital Mars' C/C++ implementation reserving some keywords for a feature of theirs.