17-12-2010, 02:11 PM
Rule 5.2 deals with identifiers declared with block scope that hide identifiers declared at an outer block, or file, scope. It does not apply to identifiers declared in other translation units. The situation described in your point (1) does not break Rule 5.2 but it does break Rule 5.5.
The code example in your point (2) also breaks Rule 5.5 because the identifier var is declared with static storage duration and is also declared at block scope. It may also break Rule 8.8 if there are other declarations of var with static storage duration in other translation units.
If your example had another function at the end, for example:
then the block-scope identifier var does hide the earlier file-scope declaration. This would break Rule 5.2.
The code example in your point (2) also breaks Rule 5.5 because the identifier var is declared with static storage duration and is also declared at block scope. It may also break Rule 8.8 if there are other declarations of var with static storage duration in other translation units.
If your example had another function at the end, for example:
Code:
int func3 ( void)
{
int var = 25;
return var;
}
Posted by and on behalf of the MISRA C Working Group