On Tue, 1 Jun 2010 21:14:53 +0200, Tim van der Molen wrote:
> I'm running i386 -current of 13 May and ran into surprising behaviour
> from gcc. Consider the following code snippet:
>
> int i;
>
> i = 1;
> if (i += 1 == 2)
> printf("%d; should be 2\n", i);
>
> i = 1;
> if ((i += 1) == 2)
> printf("%d; should be 2\n", i);
>
> The output is:
>
> 1; should be 2
> 2; should be 2
>
> It seems gcc parses the += statement wrongly: "a += b == c" should be
> interpreted as something like "(a = a + b) == c", but instead gcc
> seems to interpret it as "a = (a + b == c)". That would explain why i
> equals 1 in the first line of output.
>
> Would this be a bug in gcc or am I overlooking something?
>
> Regards,
> Tim
>
== operator has higher precedence,
http://www.difranco.net/cop2220/op-prec.htm