Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 5.2, at what scope is the rule broken?
#2
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:
Code:
int func3 ( void)
{
int var = 25;
return var;
}
then the block-scope identifier var does hide the earlier file-scope declaration. This would break Rule 5.2.
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)