Main Content

AUTOSAR C++14 Rule M2-10-1

Different identifiers shall be typographically unambiguous

Description

Rule Definition

Different identifiers shall be typographically unambiguous.

Rationale

When you use different identifiers that look typographically similar, you might inadvertently use the incorrect identifier later in your code. Such typographically ambiguous identifiers might lead to bugs that are difficult to diagnose.

Use identifiers that are unambiguously distinct. Avoid using identifiers that differ by a combination of these:

  • The use of a lowercase letter instead of an uppercase one, and vice versa.

  • 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.

Depending on the font you use, the preceding characters might look similar.

Polyspace Implementation

Polyspace® reports a defect if two identifiers differ by a combination of ambiguous characters mentioned in the preceding list. The rule checker does not consider the fully qualified names of variables when checking this rule.

Troubleshooting

If you expect a rule violation but Polyspace does not report it, see 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
}

In this example, the rule is violated when identifiers that can be confused for each other are used.

Check Information

Group: Lexical Conventions
Category: Required, Automated

Version History

Introduced in R2019a

expand all