MISRA C:2012 Dir 4.5
Identifiers in the same name space with overlapping visibility should be typographically unambiguous
Description
Directive Definition
Identifiers in the same name space with overlapping visibility should be typographically unambiguous1 .
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 digit0
.The interchange of the letter
I
and the digit1
.The interchange of the letter
I
and the letterl
.The interchange of the letter
S
and the digit5
.The interchange of the letter
Z
and the digit2
.The interchange of the letter
n
and the letterh
.The interchange of the letter
B
and the digit8
.The interchange of the letters
rn
and the letterm
.
Polyspace Implementation
The checker flags identifiers in the same scope that differ from each other only in the above characters.
In addition, the checker follows these rules:
The checker ignores identifiers that are defined in macros starting with
do
,for
,switch
, andwhile
.If two identifiers are in different scope, their uses are not ambiguous. The checker does not report violations of this rule for identifiers that are in different scopes.
The checker checks each translation unit, that is, each source file plus included headers, in isolation and later merges the findings to make sure each violation at a given location is reported only once.
If a translation unit contains both the declaration and definition, the violation is associated with the definition.
If a translation unit contains the declaration only, the violation is associated with the declaration.
As a side-effect of this rule, if a header containing two conflicting declarations is included only in the translation unit containing the corresponding definitions, you see the violation on the definitions only. If it is included in other translation units, you see the violation both on the declarations and definitions.
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
Check Information
Group: Code design |
Category: Advisory |
AGC Category: Readability |
Version History
Introduced in R2015b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.