Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

Noncompliant Code Example (Source Character Set)

DCL02-C implicitly assumes 'Global Scope' which can be confused with 'Scope within the same file'. Though it may not generate any errors, but there may be a possible violation of the rule as in the example below. Note the example below does not violate DCL32-C.
file foo.h :: int id_O; // (captial letter O)
file bar.h :: int id_0; // (numeric letter zero)

If a file foobar.h includes both foo.h and bar. h and another file foobar.c that includes foobar.h uses both id0 and idO, it is a violation of DCL02-C.

Compliant Solution (Source Character Set)

In a compliant solution, use of visully similar identifiers should be avoided in the same project scope.file foo.h :: int id_a;
file bar.h :: int id_b;

Risk Assessment

Failing to use visually distinct identifiers can result in referencing the wrong object or function, causing unintended program behavior.

...