Main Content

MISRA C:2023 Dir 4.5

Identifiers in the same name space with overlapping visibility should be typographically unambiguous

Since R2024a

Description

Directive Definition

Identifiers in the same name space with overlapping visibility should be typographically unambiguous.

Rationale

What “unambiguous” means depends on the alphabet and language in which source code is written. When you use identifiers that are typographically close, you can confuse between them.

For the Latin alphabet as used in English words, at a minimum, the identifiers should not differ by:

  • The interchange of a lowercase letter with its uppercase equivalent.

  • The presence or absence of the underscore character.

  • The interchange of the letter O and the digit 0.

  • The interchange of the letter I and the digit 1.

  • The interchange of the letter I and the letter l.

  • The interchange of the letter S and the digit 5.

  • The interchange of the letter Z and the digit 2.

  • The interchange of the letter n and the letter h.

  • The interchange of the letter B and the digit 8.

  • The interchange of the letters rn and the letter m.

Polyspace Implementation

The checker flags identifiers in the same scope that differ from each other only in the above characters. Polyspace® ignores identifiers that are defined in macros starting with do, for, switch, and while.

If two identifiers are in different scope, their uses are not ambiguous. Polyspace does not report violations of this rule for identifiers that are in different scopes.

Troubleshooting

If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

void func(void) {
	int id1_numval;
	int id1_num_val;  /* Non-compliant */

	int id2_numval;
	int id2_numVal;   /* Non-compliant */

	int id3_lvalue;
	int id3_Ivalue;   /* Non-compliant */

	int id4_xyZ;
	int id4_xy2;      /* Non-compliant */

	int id5_zerO;
	int id5_zer0;     /* Non-compliant */

	int id6_rn;
	int id6_m;        /* Non-compliant */

	int numVal;
}

void foo() {
	int numval;
}

In this example, the rule is violated when identifiers that can be confused for each other are used. Similar identifiers that are declared in different scopes are not reported as violations of this rule.

Check Information

Group: Code design
Category: Advisory
AGC Category: Readability

Version History

Introduced in R2024a