This is the mail archive of the gcc-bugs@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]

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


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