Evaluation order of index expressions

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Mon May 25 10:21:04 PDT 2015


Am Mon, 25 May 2015 09:40:34 -0700
schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:

> On 5/24/15 11:13 PM, Iain Buclaw via Digitalmars-d wrote:
> > The context here involves concurrency where bar() calls yield and
> > makes changes to foo before returning to assign the updated results.
> 
> We're not addressing that. += is not supposed to do concurrency
> magic. -- Andrei

It's not += doing the magic, it's bar(). And it's not limited to
concurrency, it happens with every side effect:

import std.stdio;
void main()
{
    int a = 0;
    int bar()
    {
        a++;
        return a;
    }
    a += bar(); // => a = a + bar()
    writeln(a);
}

DMD: 2
GDC: 1

which one is correct?




More information about the Digitalmars-d mailing list