The following identifiers have no linkage: an identifier declared to be anything other than an object or a function; an identifier declared to be a function parameter; a block scope identifier for an object declared without the storage-class specifier extern.
{
static int a; //no linkage
}
For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.
{
static int a; //no linkage
extern int a; //a should get external linkage, no?
}
GCC error: extern declaration of a follows declaration with no linkage
Can somebody explain me why do I get this error?
Thank you
means
and not
This is confusing and ambiguous; not the usual way to write a standard...
Your supposition is correct: the second declaration of
a
has external linkage. However, you get an error because your code violates a constraint in §6.7:That is, once you've declared
a
to have no linkage, you can't redeclare it again in the same scope.A valid example of this rule being invoked is: