Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 6.7.1 and local declarations with external linkage
#1
Is this rule intended to apply to variable declarations of external linkage? For example:

Code:
int main()
{
    extern int var;
    var = 4;
}

'var' is declared at block scope, refers to an object of static storage duration and is not const-qualified. Hence, it appears to be non-compliant with this rule.

However, my feeling is that it does not really fit the rationale of the rule as it does not add persistent state to the function (this declaration cannot be a definition, so some definition of var must exist outside of main). One could argue that var is effectively not local to the function containing the declaration.

Can you please clarify?

PS: I'm aware that such code does not comply with other rules as well (e.g. 6.7.2).
Reply
#2
We agree with your analysis - the rule applies to this declaration and is non-compliant (and is also non-compliant with 6.7.2).

This wasn't our intension.

We are looking at a revision along the lines of 'all local declarations should have automatic or thread_local storage duration'.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)