Using double underscores in C

I studied the book C programming a modern approach

. I found a question in it:

Why is it not recommended that the identifier contains more than one contiguous underscore (for example, in the current balance)?

Can someone explain to me why this is the case?

+2


source to share


2 answers


Identifiers starting with two underscores or underscores and an uppercase 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 identifies all identifiers listed in the corresponding subclause, and possibly declares or identifies identifiers listed in the corresponding subclause of its associated future libraries, and identifiers that are always reserved for either use or use as scope identifiers file.

  • All identifiers starting with an underscore and an uppercase letter or other underscore are always reserved for any use.
  • All identifiers starting with an underscore are always reserved for use as file-scoped identifiers in both the regular tag and the tag name.
  • Each macro name in any of the following subclauses (including future library directions) is reserved for use as indicated if any of the related headers are included; unless explicitly stated otherwise (see 7.1.4).
  • All externally linked identifiers in any of the following subclasses (including future library destinations) and are errno

    always reserved for use as externally linked identifiers. 184)
  • Each file-scoped identifier specified in any of the following subclasses (including future library destinations) is reserved for use as a macro name and as a file-scoped identifier in the same namespace if any of the associated headers are included.

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

3 If the program removes (c #undef

) any identifier macros in the first group above, the behavior is undefined.


184) & emsp; list of reserved identifiers with external linkage includes math_errhandling

, setjm

, va_copy

and va_end

.



For double underscores within names: They are difficult to distinguish from single underscores in many fonts and can be confusing. I recommend that you do not do this.

+8


source


Because it's hard to tell by looking at it if there are one or two underscores, so you're probably going to be typing current_balance when you mean current_balance.

In a similar topic, try not to mix the numbers 0 and 1 with the letters o and l and not create variables that differ only in capitalization, for example:



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

      

+2


source







All Articles