Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of notations like _NAME, __NAME, _NAME_, __NAME__

Tags:

c++

c

c#

I've seen this in countless C/C++ header and source files.
Apart from personal preference, what's the meaning of each of these different notations?

  • _NAME
  • __NAME
  • _NAME_
  • __NAME__
  • NAME_t

Quite honestly, the only one I comprehend is _NAME, which is a private member of a class (at least in C# it is).

Can someone explain the difference among them?
And if there are any other noticeable notations as such, please mention them (even in other similar languages).

Thanks!

like image 460
BeemerGuy Avatar asked Nov 23 '25 09:11

BeemerGuy


1 Answers

Names that begin with _ or __ are typically for reserved identifiers, and you should not define/create identifiers that begin with that convention. (_ with Upper Case following)

From C99 standard, 7.1.3 - "Reserved 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.

From C++03 Standard (amendment to C++98), section 17.4.3.1.2 - "Global Names"

— Each name that contains a double underscore (_ _) or begins with an underscore followed by an upper- case letter (2.11) is reserved to the implementation for any use.

— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace

like image 59
逆さま Avatar answered Nov 24 '25 23:11

逆さま



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!