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


Messages In This Thread
Rule 6.7.1 and local declarations with external linkage - by karos - 27-01-2026, 03:26 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)