IMA corner case with forward declarations of statics

Dale Johannesen dalej@apple.com
Thu Jun 24 18:48:00 GMT 2004


On Jun 24, 2004, at 11:11 AM, Zack Weinberg wrote:

> Dale Johannesen <dalej@apple.com> writes:
>
>>> Are you sure?  6.2.2p4 looks unambiguous that the first declaration
>>> does have external linkage, but I remember finding a place that said
>>> that a declaration with 'extern' and no initializer had indeterminate
>>> linkage, which the subsequent declaration with 'static' retroactively
>>> rendered into internal linkage.
>>
>> This is correct, you're thinking of 6.9.2.  Your example is valid.
>
> I don't follow your logic.

OK, I guess you are right.  6.9.2 gives this example:

static int i2=2;
extern int i2;     /*refers to previous, internal linkage */

and nothing about that section suggests that the order of declarations 
matters.
However, 6.2.2 makes it clear that the order does matter, and the 
reverse
order is undefined behavior.  (Which does not mean we have to treat it 
as
an error; you and I both thought this was valid, and I'm sure I've seen 
it
done that way.  Disallowing it is sure to break existing code.)



More information about the Gcc mailing list