In gcc, the following code prints 36

#include "stdio.h"

int func(int a) { 
  return a++ * ++a;
}

int main() {
  printf("func(5)=%d\n", func(5));
  return 0;
}

I would expect it to print 35.  The unary pre and post increment have
greater precedence over the binary multiplication.  Multiplication
associativity is left-to-right.  The LHS postincrement should return 5
and then increment to 6.  The right hand side should preincrement 6 to
7 and return 7.  Thus the binary multiplication should return 35.

But in gcc, I get 36 regardless of whether I switch the LHS and RHS.

What am I missing?

JDH

peds-pc311:~/code/lewis_test> gcc --version
gcc (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2)
_______________________________________________
Bits mailing list
[email protected]
http://www.sugoi.org/mailman/listinfo/bits

Reply via email to