This looks to be a bug in gcc (although the gcc people disagree):
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11751
http://www.gnu.org/software/gcc/bugs.html
in your case it looks like it's treating a++ * ++a like ++a * a. One
solution might be to intruduce a temporary variable...
int b = a++;
return b * ++a;
On 9/7/05, John Hunter <[EMAIL PROTECTED]> wrote:
>
> 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
>
--
Why "re-invent the wheel?"
Because this time we can make it rounder!
_______________________________________________
Bits mailing list
[email protected]
http://www.sugoi.org/mailman/listinfo/bits