Evaluation order of index expressions

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Mon May 25 10:31:53 PDT 2015


On 05/25/2015 07:21 PM, Johannes Pfau wrote:
> 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?
>
>

With left-to-right evaluation, 1 is correct. Java and C# also give 1.


More information about the Digitalmars-d mailing list