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.

Answer from maccullt on Stack Overflow

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.

Answer from maccullt on Stack Overflow
🌐
Wikipedia
en.wikipedia.org › wiki › Underscore
Underscore - Wikipedia
November 11, 2025 - Other styles are also available: doubled, dotted, and dashed. The elements may also exist in other markup languages, such as MediaWiki. The Text Encoding Initiative (TEI) provides an extensive selection of related elements for marking editorial activity (insertion, deletion, correction, addition, etc.). Unicode has a free-standing underscore _ at U+005F, inherited from ASCII, which is a legacy of the typewriter practice of underlining using backspace and overtype.
Discussions

syntax - What does double underscore ( __const) mean in C? - Stack Overflow
Can someone explain what the double underscores mean in front of const (keyword), addr (identifier) and at last __THROW. ... There's a very, very good summary of the rules for reserved identifiers here: stackoverflow.com/questions/228783/… ... Technically, the x-ref is 'reserved identifiers for C++', but there is (now) good information from the C standard too. ... In C, symbols ... More on stackoverflow.com
🌐 stackoverflow.com
python - What is the meaning of single and double underscore before an object name? - Stack Overflow
What do single and double leading underscores before an object's name represent in Python? More on stackoverflow.com
🌐 stackoverflow.com
What is double underscore for in CSS?
🌐 r/css
9
4
September 15, 2020
does the underscore or double underscore mean something in c++?
The C and C++ standards reserve symbols beginning with double underscores for implementations and they should not be defined by user programs (they can be used, but not defined). More on experts-exchange.com
🌐 experts-exchange.com
March 16, 2003
🌐
Reddit
reddit.com › r/python › what’s the meaning of single and double underscores in python?
r/Python on Reddit: What’s the Meaning of Single and Double Underscores In Python?
January 25, 2022 -

Have you ever been curious about the several meanings of underscores in Python? A little break-down?

- you can find detailed explanations and code snippets here

1️⃣ single leading underscore ("_var"): indicates that the variable is meant for internal use. This is not enforced by the interpreter and is rather a hint to the programmer.

2️⃣ single trailing underscore ("var_"): it's used to avoid conflicts with Python reserved keywords ("class_", "def_", etc.)

3️⃣ double leading underscores ("__var"): Triggers name mangling when used in a class context and is enforced by the Python interpreter. 
What this means is that it should be used to avoid your method is being overridden by a subclass or accessed accidentally.

4️⃣ double leading and trailing underscores ("__var__"): used for special methods defined in the Python language (ex. __init__, __len__, __call__, etc.). They should be avoided to use for your own attributes.

5️⃣ single underscore ("_"): Generally used as a temporary or unused variable. (If you don't use the running index of a for-loop, you can replace it with "_").

🌐
GeeksforGeeks
geeksforgeeks.org › node.js › what-does-double-underscore-__-in-front-of-a-variable-in-node-js
What does Double Underscore (__) in Front of a Variable in Node.js ? - GeeksforGeeks
July 23, 2025 - The double underscore (__) prefix is a useful convention in Node.js for managing variable scope, avoiding naming conflicts, and indicating internal or special-purpose variables. While it doesn’t have intrinsic syntactical meaning, its significance ...
🌐
Real Python
realpython.com › python-double-underscore
Single and Double Underscores in Python Names – Real Python
August 18, 2025 - Underscores in Python names indicate intent: a single leading underscore signals a non-public name, a single trailing underscore helps avoid naming conflicts, and a double leading underscore triggers name mangling for class attributes and methods.
Top answer
1 of 4
82

In C, symbols starting with an underscore followed by either an upper-case letter or another underscore are reserved for the implementation. You as a user of C should not create any symbols that start with the reserved sequences. In C++, the restriction is more stringent; you the user may not create a symbol containing a double-underscore.

Given:

extern int ether_hostton (__const char *__hostname, struct ether_addr *__addr)
__THROW;

The __const notation is there to allow for the possibility (somewhat unlikely) that a compiler that this code is used with supports prototype notations but does not have a correct understanding of the C89 standard keyword const. The autoconf macros can still check whether the compiler has working support for const; this code could be used with a broken compiler that does not have that support.

The use of __hostname and __addr is a protection measure for you, the user of the header. If you compile with GCC and the -Wshadow option, the compiler will warn you when any local variables shadow a global variable. If the function used just hostname instead of __hostname, and if you had a function called hostname(), there'd be a shadowing. By using names reserved to the implementation, there is no conflict with your legitimate code.

The use of __THROW means that the code can, under some circumstances, be declared with some sort of 'throw specification'. This is not standard C; it is more like C++. But the code can be used with a C compiler as long as one of the headers (or the compiler itself) defines __THROW to empty, or to some compiler-specific extension of the standard C syntax.


Section 7.1.3 of the C standard (ISO 9899:1999) says:

7.1.3 Reserved identifiers

Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers.

— 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.

— Each macro name in any of the following subclauses (including the future library directions) is reserved for use as specified if any of its associated headers is included; unless explicitly stated otherwise (see 7.1.4).

— All identifiers with external linkage in any of the following subclauses (including the future library directions) are always reserved for use as identifiers with external linkage.154)

— Each identifier with file scope listed in any of the following subclauses (including the future library directions) is reserved for use as a macro name and as an identifier with file scope in the same name space if any of its associated headers is included.

No other identifiers are reserved. If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined.

If the program removes (with #undef) any macro definition of an identifier in the first group listed above, the behavior is undefined.

Footnote 154) The list of reserved identifiers with external linkage includes errno, math_errhandling, setjmp, and va_end.


See also What are the rules about using an underscore in a C++ identifier; a lot of the same rules apply to both C and C++, though the embedded double-underscore rule is in C++ only, as mentioned at the top of this answer.


C99 Rationale

The C99 Rationale says:

7.1.3 Reserved identifiers

To give implementors maximum latitude in packing library functions into files, all external identifiers defined by the library are reserved in a hosted environment. This means, in effect, that no user-supplied external names may match library names, not even if the user function has the same specification. Thus, for instance, strtod may be defined in the same object module as printf, with no fear that link-time conflicts will occur. Equally, strtod may call printf, or printf may call strtod, for whatever reason, with no fear that the wrong function will be called.

Also reserved for the implementor are all external identifiers beginning with an underscore, and all other identifiers beginning with an underscore followed by a capital letter or an underscore. This gives a name space for writing the numerous behind-the-scenes non-external macros and functions a library needs to do its job properly.

With these exceptions, the Standard assures the programmer that all other identifiers are available, with no fear of unexpected collisions when moving programs from one implementation to another5. Note, in particular, that part of the name space of internal identifiers beginning with underscore is available to the user: translator implementors have not been the only ones to find use for “hidden” names. C is such a portable language in many respects that the issue of “name space pollution” has been and is one of the principal barriers to writing completely portable code. Therefore the Standard assures that macro and typedef names are reserved only if the associated header is explicitly included.

5 See §6.2.1 for a discussion of some of the precautions an implementor should take to keep this promise. Note also that any implementation-defined member names in structures defined in <time.h> and <locale.h> must begin with an underscore, rather than following the pattern of other names in those structures.

And the relevant part of the rationale for §6.2.1 Scopes of identifiers is:

Although the scope of an identifier in a function prototype begins at its declaration and ends at the end of that function’s declarator, this scope is ignored by the preprocessor. Thus an identifier in a prototype having the same name as that of an existing macro is treated as an invocation of that macro. For example:

    #define status 23
    void exit(int status);

generates an error, since the prototype after preprocessing becomes

   void exit(int 23);

Perhaps more surprising is what happens if status is defined

   #define status []

Then the resulting prototype is

   void exit(int []);

which is syntactically correct but semantically quite different from the intent.

To protect an implementation’s header prototypes from such misinterpretation, the implementor must write them to avoid these surprises. Possible solutions include not using identifiers in prototypes, or using names in the reserved name space (such as __status or _Status).

See also P J Plauger The Standard C Library (1992) for an extensive discussion of name space rules and library implementations. The book refers to C90 rather than any later version of the standard, but most of the implementation advice in it remains valid to this day.

2 of 4
19

Names with double leading underscores are reserved for use by the implementation. This does not necessarily mean they are internal per se, although they often are.

The idea is, you're not allowed to to use any names starting with __, so the implementation is free to use them in places like macro expansions, or in the names of syntax extensions (e.g. __gcnew is not part of C++, but Microsoft can add it to C++/CLI confident that no existing code should have something like int __gcnew; in it that would stop compiling).

To find out what these specific extensions mean, i.e. __const you'll need to consult the documentation for your specific compiler/platform. In this particular case, you should probably consider the prototype in the documentation (e.g. http://www.kernel.org/doc/man-pages/online/pages/man3/ether_aton.3.html) to be the function's interface and ignore the __const and __THROW decorations that appear in the actual header.

Find elsewhere
🌐
Quora
quora.com › What-does-a-double-underscore-mean-in-coding
What does a double underscore mean in coding? - Quora
Answer: It means different things in different contexts. Usually, those different things are conventions related to specific languages or frameworks. In some cases, it’s more than a convention.
Top answer
1 of 16
1685

Single Underscore

In a class, names with a leading underscore indicate to other programmers that the attribute or method is intended to be be used inside that class. However, privacy is not enforced in any way. Using leading underscores for functions in a module indicates it should not be imported from somewhere else.

From the PEP-8 style guide:

_single_leading_underscore: weak "internal use" indicator. E.g. from M import * does not import objects whose name starts with an underscore.

Double Underscore (Name Mangling)

From the Python docs:

Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped. This mangling is done without regard to the syntactic position of the identifier, so it can be used to define class-private instance and class variables, methods, variables stored in globals, and even variables stored in instances. private to this class on instances of other classes.

And a warning from the same page:

Name mangling is intended to give classes an easy way to define “private” instance variables and methods, without having to worry about instance variables defined by derived classes, or mucking with instance variables by code outside the class. Note that the mangling rules are designed mostly to avoid accidents; it still is possible for a determined soul to access or modify a variable that is considered private.

Example

>>> class MyClass():
...     def __init__(self):
...             self.__superprivate = "Hello"
...             self._semiprivate = ", world!"
...
>>> mc = MyClass()
>>> print mc.__superprivate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: myClass instance has no attribute '__superprivate'
>>> print mc._semiprivate
, world!
>>> print mc.__dict__
{'_MyClass__superprivate': 'Hello', '_semiprivate': ', world!'}
2 of 16
589
  • _foo: Only a convention. A way for the programmer to indicate that the variable is private (whatever that means in Python).

  • __foo: This has real meaning. The interpreter replaces this name with _classname__foo as a way to ensure that the name will not overlap with a similar name in another class.

  • __foo__: Only a convention. A way for the Python system to use names that won't conflict with user names.

No other form of underscores have meaning in the Python world. Also, there's no difference between class, variable, global, etc in these conventions.

🌐
ASCII Code
ascii-code.com › character › ‗
‗ - double low line - ASCII Code
Detailed information about ASCII character ‗, also known as the double low line
🌐
Reverso Dictionnaire
dictionnaire.reverso.net › anglais-francais › double+underscore+symbol
Traduction double underscore symbol en Français | Dictionnaire Anglais-Français | Reverso
→ a lone skier gliding along smooth double tracks → an extremely nasty double murder a double helping une double portion → a double helping of ice cream double in size, → twice as big , deux fois plus grand → Let the loaves rise until double in size.
🌐
Reddit
reddit.com › r/css › what is double underscore for in css?
r/css on Reddit: What is double underscore for in CSS?
September 15, 2020 -

I'm new to web-dev and CSS. I have a question. What is double underscore for, and why would you use that? I have seen it in in one of the CSS tutorials and it does not explain why one would use double underscore in style.css. Any help will be greatly appreciated. Thank you.

🌐
Experts Exchange
experts-exchange.com › questions › 20552640 › does-the-underscore-or-double-underscore-mean-something-in-c.html
Solved: does the underscore or double underscore mean something in c++? | Experts Exchange
March 16, 2003 - In simple term: Double __ : reserved identifiers that are compiler dependent (introduced by vendor, not by standard C++) ex: __fastcall (BCB); __declspec (VC++) Single _ : reserved identifiers that are platform (machine/operating system) dependent ...
🌐
DokuWiki User Forum
forum.dokuwiki.org › d › 18515-inserting-a-double-underscore
Inserting a double underscore - DokuWiki User Forum
November 22, 2020 - Community Discussions, Questions and Answers for the OpenSource wiki software DokuWiki.
🌐
dbader.org
dbader.org › blog › meaning-of-underscores-in-python
The Meaning of Underscores in Python – dbader.org
May 23, 2017 - A double underscore prefix causes the Python interpreter to rewrite the attribute name in order to avoid naming conflicts in subclasses.
🌐
DataCamp
datacamp.com › tutorial › role-underscore-python
Underscore in Python Tutorial : What is the purpose and meaning of _ & __ | DataCamp
October 26, 2018 - Double Pre Underscores tells the Python interpreter to rewrite the attribute name of subclasses to avoid naming conflicts.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 2428229 › double-underscore-icon-on-task-bar
double underscore icon on task bar - Microsoft Q&A
May 28, 2010 - From now on you will see the Double Underline button on your Quick Access toolbar (next to the Microsoft Office button if you haven't used it before).
🌐
Microsoft
devblogs.microsoft.com › dev blogs › the old new thing › on leading underscores and names reserved by the c and c++ languages
On leading underscores and names reserved by the C and C++ languages - The Old New Thing
December 14, 2024 - Yeah, that’s why “the rules for C happen to match the C++ rules” is not quite true. C++ reserves identifiers that contain double underscores anywhere, but C does not.
🌐
Reddit
reddit.com › r/cpp › usage of underscores in identifiers (in modern c++)
r/cpp on Reddit: Usage of underscores in identifiers (in modern C++)
March 13, 2025 -

In one of my projects, I heavily use underscores in identifiers. None of the crazy stuff like "a leading underscore followed by a capital letter", that is so strongly reserved for the implementation. But many of my identifiers end with underscores or contain underscores in the middle.

Seems like every developer has a different opinion about this, and in every discussion, the holy ANSI-C standard is cited:

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

However, ANSI-C defines also other restrictions, that seem a little bit outdated to me. In my project, I use C++20, soon switching to C++23; the code is C++-styled and not C-styled like in the glorious old days of programming...

Just wanted to hear your thoughts about the underscore topic. Do you use it? If not, are there reasonable points against it, nowadays?

🌐
GeeksforGeeks
geeksforgeeks.org › python › single-aad-double-underscores-in-python
Single and Double Underscores in Python - GeeksforGeeks
July 23, 2025 - Double underscores are integral to defining special methods, often referred to as "magic methods" or "dunder methods." These methods, such as __init__ and __str__, have double underscores at the beginning and end of their names.