F
Flash Gordon
Old said:Firstly, it is /tentative definition/, not declaration.
Your correct, I meant tentative definition.
Also, Mark McIntyre was taking about objects.
As am I mainly, I just mentioned that functions where different because
with a function declaration the extern keyword does not matter.
The tentative definition in question has external linkage.
Yes, which means that it can be accessed from another translation unit.
The object it identifies must also have external linkage --
whether it is later explicitly declared or not.
Mark McIntyre's comment seems correct; I don't understand the
distinction you draw between an object being "an extern",
vs. "having external linkage".
Possibly because the standard talks about linkage and the extern keyword
separately?
When talking about linkage, the defines three types of linkage, none,
internal and external.
None is irrelevant to our discussion since the standard say, "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."
Internal linkage is irrelevant since that is static objects, to quote,
"If the declaration of a file scope identifier for an object or a
function contains the storage class specifier static, the identifier has
internal linkage."
So obviously a variable either declared extern or defined at file scope
has external linkage. I.e. the linkage is external in the translation
unit that defines the storage and the translation units that only
reference it.
You have accepted that something like:
int i;
is a tentative definition when given at file scope. I also quoted that
at the end of the translation unit that becomes a an actual definition.
Annex A.2 Undefined behaviour, is only informative, not normative, but
it gives the clearest statement that having multiple definitions (which
having "int i;" at file scope in more than one translation unit gives
you) is undefined behaviour. It gives as one example of undefined behaviour:
"An identifier with external linkage is used, but in the program there
does not exist exactly one external definition for the identifier, or
the identifier is not used and there exist multiple external definitions
for the identifier (6.9)."
Two definitions, whether the variable is used or not, falls fouls of
this rule.