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?
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
errnoare 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.
184) The list of reserved identifiers with external linkage includes
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.
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;