IMA corner case with forward declarations of statics

Geoff Keating geoffk@geoffk.org
Thu Jun 24 02:58:00 GMT 2004


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.

We should probably print a proper error message.



More information about the Gcc mailing list