gcc rejects enum/int compatibility

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

 



Hello,

Compiling the following C code with gcc 4.7.2 (Linux, i386):

   extern enum { red, green, blue } foo;

   int foo = green;

   int main(void)
   {
      printf("foo = %d\n", foo);
      return 0;
   }

results in the following diagnostics:

foo.c:3:8: error: conflicting types for 'foo'
foo.c:1:37: note: previous declaration of 'foo' was here

However, the C 2011 Standard says:

   6.2.7 ... All declarations that refer to the same object or function
   shall have compatible type ...

   6.7.2.2 ... Each enumerated type shall be compatible with ...
   a signed integer type ...

Please explain me what is wrong.

Thanks,

Andrew Makhorin






[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