24151

Use of double underscore in C [closed]

I was studying C programming a modern approach book. I found a question in it:

Why is it not a good idea for an identifier to contain more than one adjacent underscore (As in current__balance for example)?

Can anyone explain to me why is it so?

Answer1:

Identifiers that begin with two underscores or an underscore and a capital letter are reserved by the C standard and should not be used in your own code, cf. ISO 9899:2011 §7.1.3 ¶1 #1:

7.1.3 Reserved identifiers

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

    <li>All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.</li> <li>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.</li> <li>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).</li> <li>All identifiers with external linkage in any of the following subclauses (including the future library directions) and errno are always reserved for use as identifiers with external linkage.<sup>184)</sup></li> <li>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.</li> </ul>

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

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

    <hr>

    184) The list of reserved identifiers with external linkage includes math_errhandling, setjm, va_copy, and va_end.

    For double underscores inside names: These are hard to tell apart from single underscores in many typefaces and lead to confusion. I recommend you to avoid doing that.

    Answer2:

    Because it's hard to tell looking at it whether there's one or two underscores, so you're likely to type current_balance when you meant current__balance.

    On a similar theme, try not to mix the numbers 0 and 1 with the letters o and l, and don't make variables that only differ in capitalization, for example:

    bool boo1; bool b00l; int i_byte; int i_Byte;

Recommend

  • Best place to define a struct for a library [closed]
  • Facebook messenger account linking, how to use it?
  • Using 'end' as column name in Ruby on Rails (MySQL)
  • How can you examine lib files?
  • Unable to quote table name in PDO with MSSQL
  • How to find where all of the space in a SQLServer database is being used
  • Example from three.js but how to implement using SceneKit?
  • regex to grab text if code exists
  • Django: nested content blocks with the same name
  • ipinfodb lookup returns countryCode 'RD'
  • Should the plus in tel URIs be encoded?
  • Context is Missing when using Unobtrusive ajax in asp.net mvc-3
  • CDATA getting stripped in lxml even after using strip_cdata=False
  • Add completion handler to presentViewControllerAsSheet(NSViewController)?
  • Local Notifications for Corona SDK (Android)
  • Why Javascript doesn't include reserved keywords such as “Object”, “Array”, “Function”, “Number
  • SWIFT uiviewcontroller init
  • Random characters in CSS class names
  • QML ListElement pass list of strings
  • Grow Animation for Floating Action Button
  • time_t conversion format question
  • c#.NET USB device persistent identifier
  • DELETE FROM … reporting syntax error at or near “.”
  • What do getresuid() and setresuid() do?
  • SQL Server 2005, Caches and all that jazz
  • Process.PrivateMemorySize64 returning committed memory instead of private
  • help('modules') crashing? Not sure how to fix
  • MySQL: Difference between `… ADD INDEX(a); … ADD INDEX(b);` and `… ADD INDEX(a,b);`?
  • Can I update/select from a table in one query?
  • Tools for understanding HTML layout
  • Can I use AllJoyn Framework for Wifi Direct in iOS?
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • How to make R's read_csv2() recognise the text characters properly
  • How can I sort a a table with VBA with given text condition?
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Why winpcap requires both .lib and .dll to run?
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • php design question - will a Helper help here?
  • reshape alternating columns in less time and using less memory