You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Identifiers must be unique to prevent confusion as to which variable or function is being referenced. Implementations can allow additional non-unique characters to be appended to the end of an identifier--making the identifieres appear unique while actually being indistinguishable.

To guarantee identifiers are unique, you must first determine the number of significant characters recognized by (the most restrictive) compiler you are using. This assumptions must be documented in the code.

The standard defines the following minimum requirements:

  • 63 significant initial characters in an internal identifier or a macro name (each universal character name or extended source character is considered a single character)
  • 31 significant initial characters in an external identifier (each universal character name specifying a short identifier of 0000FFFF or less is considered 6 characters, each
    universal character name specifying a short identifier of 00010000 or more is considered 10 characters, and each extended source character is considered the same number of characters as the corresponding universal character name, if any)

Restriction of the significance of an external name to fewer than 255 characters in the standard (considering each universal character name or extended source character as a single character) is an obsolescent feature that is a concession to existing implementations. Therefore, it is not necessary to comply with this restriction as long as your identifiers are unique and your assumptions concering the number of significant characters is documented.

Non-Compliant Example

Assuming your compiler implements the minimum requirements for signficant characters required by the standard, the following example is non-compliant:

extern int \U00010401\U00010401\U00010401\U00010401[100];
extern int \U00010401\U00010401\U00010401\U00010402[100];

In this example, both external identifiers consist of four universal characters but only the first three characters are unique. In practice, this means that both identifiers are referring to othe same integer array.

Compliant Solution

In the compliant solution, the signficant characters in each identifier vary.

extern int \U00010401\U00010401\U00010401\U00010401[100];
extern int \U00010402\U00010401\U00010401\U00010401[100];

References

  • No labels