This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Is this a bug?
- From: Songtao Chen <songtao at cisco dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 02 Jan 2003 16:21:37 -0500
- Subject: Is this a bug?
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