This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Incorrect casting?


Hi,
the following piece of code produces different output on svn trunk and
gcc-4_4-branch:

#include <stdio.h>
int main()
{
        struct { unsigned bar:1; } foo;

        foo.bar = 0x1;

        printf("%08x\n", (unsigned char)(foo.bar * 0xfe));
        printf("%08x\n", (unsigned char)(foo.bar * 0xff));

        return 0;
}

monstter@yggdrasil /data/tmp $ gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-svn/configure --enable-stage1-languages-c
--enable-languages=c,c++
Thread model: posix
gcc version 4.4.4 20100309 (prerelease) (GCC)
monstter@yggdrasil /data/tmp $ ./a.out
000000fe
00000001

monstter@yggdrasil /data/tmp $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-svn/configure --enable-stage1-languages-c
--enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20100309 (experimental) (GCC)
monstter@yggdrasil /data/tmp $ ./a.out
000000fe
000000ff

Is there something illegal in this code or is it a bug somewhere?

Thanks,
Marcin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]