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]

bug in 4.1.1?


When compiling the following the code with gcc 4.1.1 without optimization, the output is wrong.

gcc -v is

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure --prefix=/home/jb/local
Thread model: posix
gcc version 4.1.1

<=====code=====>

#include<stdio.h>

int main()
{
        int b[2] = {3, 5};

b[0] ^= b[1] ^= b[0] ^= b[1];

printf("b[0] = %d, b[1] = %d\n", b[0], b[1]);

        return 0;
}

<=====/code====>

with -O0, the output is

b[0] = 0, b[1] = 3

whereas with -O1 (or -O2 or -O3), it's

b[0] = 5, b[1] = 3

i was able to reproduce this on x86, HP/UX and AIX

Please, tell me if you need any more info.


-jb -- Endless Loop: n.,see Loop, Endless. Loop Endless: n.,see Endless Loop. -Anonymous


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