[previous] MISRA-C:2004  Rule  5.2:  (Required) [next] Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier.
The terms outer and inner scope are defined as follows. Identifiers that have file scope can be considered as having the outermost scope. Identifiers that have block scope have a more inner scope. Successive, nested blocks, introduce more inner scopes. This rule disallows the case where a second inner definition hides an outer definition. If the second definition does not hide the first definition, then this rule is not violated.

Hiding identifiers with an identifier of the same name in a nested scope leads to code that is very confusing. For example:

int16_t i;
{
    int16_t i;        /* This is a different variable                    */
 		      /* This is not compliant                           */
    i = 3;            /* It could be confusing as to which i this refers */
}


QAC messages that encompass this guideline:

2547 This declaration of tag '%s' hides a more global declaration.
3334 This declaration of '%s' hides a more global declaration.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents