...
- No other variable should share the name of a global variable.
- A block should not declare a variable the same name as a variable declared in any block that contains it.
...
In this example, the programmer sets the value of the msg variable, expecting to reuse that it outside the block. Due to the reuse of the same variable name, however, the outside msg
variable value is not changed.
...
Exceptions
When the block is small, although still not desirable, the danger of reusing variable names is mitigated by the visibility of the immediate declaration. Even in this case, however, variable name reuse is not desirable.
References
- ISO/IEC 9899-1999 5.2.4.1 Translation limits
- MISRA 04 Rule 5.2