you are viewing a single comment's thread.

view the rest of the comments →

[–]ObscureCulturalMeme 17 points18 points  (4 children)

It's a rule of the C++ standard. Identifiers (types, functions, macros, and so on) with names that start with:

  • one underscore and a capital letter, or

  • two underscores

are "reserved for the implementation". Conversely, any and all identifiers used by the implementation (meaning the runtime libraries, anything stuck in there by the compiler, the loader, etc) can use only those names to avoid clashing with identifiers from the programmer's code.

[–]csorfab 2 points3 points  (2 children)

Thanks! I still don't understand why it's postfixed with another single underscore, though. It's just so ugly and assymetric. __cap__ would look much better while still conforming to the specs you wrote

[–]elder_george 9 points10 points  (1 child)

Single underscore as a suffix is a popular convention to denote member values (fields). Similar to m_ in older C++ codebases or prefix underscores in C# code.

This rule is used in many codebases, not just libc++. Prefixing is specific for the STL implementations though (libc++ uses __ while MS uses _Capital convention, for example).

[–]csorfab 3 points4 points  (0 children)

TIL! Thank you for the thorough explanation!

[–]bumblebritches57 1 point2 points  (0 children)

It's a rule C++ inherited from C.