Is this a bug?
Songtao Chen
songtao@cisco.com
Thu Jan 2 21:21:00 GMT 2003
Hi there,
It appears to be a bug to me.
* gcc version:
gcc.c2.95.3
* source code: bug.c
#include<stdio.h>
int main(void)
{
int r, i;
i = 0;
r = ++i % 2;
printf("test 1 : r = %d, i = %d\n", r, i);
i = 0;
r = i++ % 2;
printf("test 2 : r = %d, i = %d\n", r, i);
i = 0;
r = (++i) % 2;
printf("test 3 : r = %d, i = %d\n", r, i);
i = 0;
r = (i++) % 2;
printf("test 4 : r = %d, i = %d\n", r, i);
i = 0;
r = (i+1) % 2;
printf("test 5 : r = %d, i = %d\n", r, i);
return 0;
}
* compile command:
gcc.c2.95.3 bug.c
* type of machine:
SunOS ott-view1 5.6 Generic_105181-28 sun4u sparc SUNW,Ultra-Enterprise
...
* output :
test 1 : r = 1, i = 1
test 2 : r = 0, i = 1
test 3 : r = 1, i = 1
test 4 : r = 0, i = 1
test 5 : r = 1, i = 0
Expecting r = 1 in test 4, because use of brackets.
Thanks,
Songtao
More information about the Gcc-bugs
mailing list