Evaluation order of index expressions
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 24 16:49:00 PDT 2015
On 5/24/15 3:36 PM, Iain Buclaw via Digitalmars-d wrote:
> On 25 May 2015 00:20, "Andrei Alexandrescu via Digitalmars-d"
> <digitalmars-d at puremagic.com <mailto: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.
Even better - the front end could force the sequencing.
> 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 LTR is the most sensible in all cases. -- Andrei
More information about the Digitalmars-d
mailing list