MISRA C:2023 Rule 5.3
An identifier declared in an inner scope shall not hide an identifier declared in an outer scope
Since R2024a
Description
Rule Definition
An identifier declared in an inner scope shall not hide an identifier declared in an outer scope.
Rationale
If two identifiers have the same name but different scope, the identifier in the inner scope hides the identifier in the outer scope. All uses of the identifier name refers to the identifier in the inner scope. This behavior forces the developer to keep track of the scope and reduces code readability.
Polyspace Implementation
Polyspace® considers two names as distinct if there is a difference between their
first 63 characters. In C90, the difference must occur between the first 31
characters. To use the C90 rules checking, use the value c90
for
the option C
standard version (-c-version)
. You can change the number of
characters compared using the option
-code-behavior-specifications
. See -code-behavior-specifications
.
If the identifier that is hidden is declared in a Standard Library header and you do not provide the header for the analysis, the issue is not shown. To see potential conflicts with identifiers declared in a Standard Library header, provide your compiler implementation of the headers for the Polyspace analysis. See Provide Standard Library Headers for Polyspace Analysis.
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: Identifiers |
Category: Required |
AGC Category: Advisory |
Version History
Introduced in R2024a