I'm a bit confused by the wording in 6.9 p5 of N2310 C18:
If an identifier declared with external linkage is used in an expression (other than as part of the operand of a
sizeofor_Alignofoperator whose result is an integer constant), somewhere in the entire program there shall be exactly one external definition for the identifier; otherwise, there shall be no more than one. 164)
QUESTION: Is it obvious from this quote that the external definition somewhere in the program (if any) should also declare an identifier with external linkage?
As I emphasized somewhere in the entire program there shall be exactly one external definition for the identifier. It does not specify which linkage the definition should declare the identifier with. Example:
tu1.c:
int a = 10;
tu2.c:
static int a = 20;
Formally speaking we have one external definition for identifier a declared in tu1.c and another one in tu2.c so we could apply the quote I cited above to this example.
Although to denote the same entity identifiers declared in different should all be declared with external linkage as specified in 6.2.2/2:
In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or function.
Which is not the case here.
static int a = 20;intu2.cdoes not declareaas having external linkage. On the contrary, it has explicitly 'local' linkage. Or have I missed the point? (Which is not unusual.) - Adrian Moletu2.cdoes not cause undefined behaviour - M.M