gcc-2.95.2, '-O', operator '%=' gives wrong result

Krakowczyk, Andreas Andreas.Krakowczyk@fujitsu-siemens.com
Wed Sep 27 07:05:00 GMT 2000


Hi there,

The following test program gives wrong results when compiled with option
'-O' but works fine without optimization.
The compiler version I use is gcc-2.95.2 on mips-sni-sysv4 .
The compiler command line is 'gcc -O test.c && ./a.out'.

This is the test program:

main () {
    signed char a = 127;
    signed char b = 126;
    unsigned int c = 4294967295U;

    printf ("a =   0x%02X (%d)\n", a, a);
    printf ("b =   0x%02X (%d)\n", b, b);
    printf ("c = 0x%04X (%d)\n",   c, c);

    a %= b % c;

    if (a == 1)
	printf ("test passed, %s results in %d\n", "a %= b % c", a);
    else
	printf ("test FAILED, %s results in %d\n", "a %= b % c", a);
}

Kind regards,

Andreas Krakowczyk
FSC EP LP AD C++
Andreas.Krakowczyk@fujitsu-siemens.com


More information about the Gcc-bugs mailing list