This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: IMA corner case with forward declarations of statics


Geoff Keating <geoffk@geoffk.org> writes:

> On 23/06/2004, at 7:43 PM, Zack Weinberg wrote:
>
>> Consider the following test case:
>>
>> A.c:
>>     int foo = 12;
>> B.c:
>>     extern int printf(const char *, ...);
>>     extern int foo;
>>
>>     int main(void)
>>     {
>>         printf("%d\n", foo);
>>         return 0;
>>     }
>>
>>     static int foo = 14;
>>
>> Taken together, this is a correct C program which should print 14.
>
> Actually, this is a violation of 6.2.2 paragraph 7,
>
>> If, within a translation unit, the same identifier appears with both
>> internal and external linkage, the behavior is undefined.

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.  If you are certain, I'll be happy to
make c-decl.c even pickier. :-)

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]