Why error "variable previously declared ‘static’ redeclared ‘extern’"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following code gives me an error when trying to build with gcc-4.8:

#include <stdio.h>
#include <stdlib.h>

static int i5 = 30;

int main(void)
{
    int i5 = 12;
    printf("i5: %d\n", i5);
    {
        extern int i5;
        printf("i5: %d\n", i5);
    }

    printf("i5: %d\n", i5);
    exit(0);
}

main.c:11:14: error: variable previously declared ‘static’ redeclared ‘extern’

However, it compiles with clang 3.0. I don't understand what does GCC
want to tell me with this message. As far I know, `extern' must refer
to a variable defined with an internal or external linkage so it this
case it must refer to static i5, not i5 defined in the first line of
main(). I looked into C standard section 6.2.2 but found nothing that
would justify this error message. I know this is GCC mailing group so
don't take it personally but my current guess is that GCC is simply
overzealous and less smart than Clang, is that right?





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux