Evaluation order of index expressions

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sun May 24 16:09:54 PDT 2015


On 05/25/2015 12:36 AM, Iain Buclaw via Digitalmars-d wrote:
>
>  > This comes up once in a while. We should stick with left to right
> through and through. It's a "simple" matter of getting somebody on the
> compiler team to find the time for it. -- Andrei
>  >
>
> I find it is not as clear cut as that.  In gdc, there is a compiler flag
> that tells the optimizer to honour left to right evaluation, and because
> of both what you say and the agreement of others, it seems natural to
> have this turned on by default.
>
> However, this has an interesting side effect with operations with side
> effects.  Ie: foo += bar() could either produce expected or surprising
> results.
>
> Hint, the LTR order - foo = foo + bar() - gives the most surprise in my
> experience from users.
>

I think I still don't get it. What is the surprise? That bar() is 
evaluated before the value is written to foo?


More information about the Digitalmars-d mailing list