long bit-fields with g++ 4.4.1
Vineet Soni
vsoni@tilera.com
Thu Mar 11 20:31:00 GMT 2010
The integral promotion behavior of long bit-fields has changed with g++ 4.4.1 on
x86_64-linux, and appears broken. Consider:
#include <stdio.h>
#define T unsigned long
int main()
{
struct { T f : 33; } s = { 1UL << 32 };
printf("%lx %lx %lx\n", (T)s.f, (T)(s.f << 1), (T)((s.f << 1) >> 1));
struct { T f : 16; } t = { 1UL << 15 };
printf("%lx %lx %lx\n", (T)t.f, (T)(t.f << 17), (T)((t.f << 17) >> 17));
return 0;
}
Based on my interpretation of the C++ standard, the expected output is:
100000000 200000000 100000000
8000 100000000 8000
The actual output is:
$ g++-4.4.1 -Wall -pedantic x.c; ./a.out
100000000 200000000 100000000
8000 0 0
Is this a bug?
Note that 4.0.2 matches the expected output:
$ g++-4.0.2 -Wall -pedantic x.c; ./a.out
100000000 200000000 100000000
8000 100000000 8000
GCC versions used:
$ gcc-4.0.2 -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../../src/gcc-4.0.2/configure
--prefix=/home/global/Linux-x86_64-rhel3/encap/gcc-4.0.2 --disable-libgcj
--enable-languages=c,c++
Thread model: posix
gcc version 4.0.2
$ gcc-4.4.1 -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ./configure
--prefix=/home/global/Linux-x86_64-rhel5/encap/gcc-4.4.1 --disable-libgcj
--enable-languages=c,c++
--with-mpfr=/home/global/Linux-x86_64-rhel5/encap/mpfr-2.4.1
Thread model: posix
gcc version 4.4.1 (GCC)
-- Vineet
More information about the Gcc-help
mailing list