5
-red
14d

Why do some variable names start with an _ in C/C++ ? I personally do not like such naming.

Comments
  • 8
    Because they are reserved and must not be used by the application. From the C standard, chapter 7 Libraries, subchapter 7.3.1 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.

    Conclusion: you should not care about variables with underscore in any way, and you should not use them.
  • 1
    Google's C++ style guide has underscore at the end of a class member variable. Maybe underscore at the start is just a convention that some people use. An underscore at the start is sometimes even reserved.
  • 2
    As Fast-Nop said, _Ugly and __ugly are reserved for the implementation to use. _ugly identifiers are probably fine for private members of classes though and they're probably used for implementation details, which you shouldn't care for most of the time
  • 3
    @Fast-Nop @electrineer @RealKC I've found some people using such variable naming in their application along with other ways of naming. I found it annoying and non-uniform.
  • 3
    @-red well these people are violating the C standard and risk that their application may break at any compiler or library update, or that it's not portable.
  • 1
    I tend to name my functions which are not part of my application's public API with underscores in the beginning of the name to denote being private/not being used publicly.
  • 1
    I use it for class variables in c#, for example
    private string _connectionString;
Your Job Suck?
Get a Better Job
Add Comment