...
Make the initial portions of long identifiers unique for easier recognition. This also helps prevent errors resulting from non-unique identifiers. (See rule DCL32-C. Guarantee that mutually visible identifiers are unique.)
In addition, the larger the scope of an identifier, the more descriptive its name should be. It may be perfectly appropriate to name a loop control variable i, but the same name would likely be confusing if it named a file scope object or a variable local to a function more than a few lines long. See also recommendations DCL01-C. Do not reuse variable names in subscopes and DCL19-C. Use as minimal a scope as possible for all variables and functions.
...
DCL02-C implicitly assumes 'Global Scope' global scope, which can be confused with 'Scope scope within the same file'. Though Although it may not generate any errors, but there may be a possible violation of the rule may occur, as in the following example below. Note the example below does . Note this example does not violate DCL32-C. Guarantee that mutually visible identifiers are unique
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
int id_O; // (captial letter O)
|
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
int id_0; // (numeric letter zero)
|
...
In a compliant solution, use of visully visually similar identifiers should be avoided in the same project scope.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
int id_a;
|
In file bar.h:
| Code Block | ||||
|---|---|---|---|---|
| ||||
int id_b;
|
Risk Assessment
Failing to use visually distinct identifiers can result in referencing the wrong object or function, causing unintended program behavior.
...
Tool | Version | Checker | Description | section||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 67 X section | Fully Implementedsectionimplemented | |||||||||
Compass/ROSE |
|
| section | ||||||||
| idntsiml section | Fully Implementedimplemented |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
CERT C++ Secure Coding Standard: DCL02-CPP. Use visually distinct identifiers
ISO/IEC 9899:19992011 Section 5.2.4.1, "Translation limits"
ISO/IEC TR 24772 "AJN Choice of Filenames and other Other External Identifiers," "BRS Leveraging human experienceHuman Experience," and "NAI Choice of Clear Names"
...