Evaluation order of index expressions

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Sun May 24 15:36:25 PDT 2015


On 25 May 2015 00:20, "Andrei Alexandrescu via Digitalmars-d" <
digitalmars-d at puremagic.com> wrote:
>
> On 5/24/15 1:29 PM, Timon Gehr wrote:
>>
>> BTW, the documentation contradicts itself on evaluation order:
>> http://dlang.org/expression.html
>
>
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150525/7e9c42ec/attachment.html>


More information about the Digitalmars-d mailing list