On Wednesday, 26 September 2012 at 15:12:05 UTC, Alex Rønne Petersen wrote:
On 26-09-2012 15:34, monarch_dodra wrote:
[SNIP]

No it isn't. There's a perfectly sensible, sane, and intuitive fix for this: always evaluate arguments left-to-right. No exceptions.

It's not that complicated.

You know, I think you are right on second though. However, it is a matter of not mistaking "left to right evaluation of arguments" with normal the associative behavior of operators.

EG: (a = (b = c) = d):
*a is evaluated
*b is evaluated
*c is evaluated
*(b = c) is evaluad into a temp called bc
*d is evaluated
*bc = d is evaluated into bcd
*a = bcd is evaluated.

So back to my example: (where i starts at 1)
x[i++] = ++i + 1;
*i++ is evaluated to 1, and i is now 2.
*x[i++] is now a reference to x[1]
*++i is evaluated to 3
*++i + 1 is 4
*x[1] becomes 4

Yeah... it looks like it works.

Reply via email to