This problem can be reproduced using the attached testcase. In GCC 3.2.3 (i386-redhat-linux), it works as expected: > ~ % gcc -v > Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs > Configured with: ../configure --prefix=/usr --mandir=/usr/share/man > --infodir=/usr/share/info --enable-shared --enable-threads=posix > --disable-checking --with-system-zlib --enable-__cxa_atexit > --host=i386-redhat-linux > Thread model: posix > gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-54) > ~ % gcc -o foo foo.c > ~ % ./foo > 100000002 100000002
In GCC 4.1.2 (x86_64-redhat-linux), apparently the value FOO is interpreted as a 32-bit integer before the left shift; the bizarre thing is that casting to Foo (which should be unnecessary) avoids this. > ~ % gcc -v > Using built-in specs. > Target: x86_64-redhat-linux > Configured with: ../configure --prefix=/usr --mandir=/usr/share/man > --infodir=/usr/share/info --enable-shared --enable-threads=posix > --enable-checking=release --with-system-zlib --enable-__cxa_atexit > --disable-libunwind-exceptions --enable-libgcj-multifile > --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk > --disable-dssi --enable-plugin > --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic > --host=x86_64-redhat-linux > Thread model: posix > gcc version 4.1.2 20070626 (Red Hat 4.1.2-14) > ~ % gcc -o foo foo.c > foo.c: In function 'main': > foo.c:13: warning: left shift count >= width of type > ~ % ./foo > 2 100000002 When I asked about this on gcc-help, Andrew Haley <[EMAIL PROTECTED]> wrote: > It's a bug. C99 says an enumerated type shall be large enough to > represent all its members, and that when promoting the rank of the > enumerated type shall equal the rank of the compatible integer type. -- Summary: 64-bit enumerator incorrectly demoted to 32 bits Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jjk at acm dot org GCC host triplet: x86_64-redhat-linux GCC target triplet: x86_64-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36651