Order of evaluation of a += a++;

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 4 19:54:20 PDT 2015


On Tuesday, 31 March 2015 at 08:17:31 UTC, Andrei Alexandrescu 
wrote:
> On 3/31/15 12:18 AM, Orvid King wrote:
>>
>> I might be a bit confused here, but from what you're saying:
>> b += a++;
>> and
>> b += ++a;
>>
>> Are doing the same thing in DMD?
>
> No. Lowering of e1 += e2++ is:
>
> e1 += e2++
>
> -\>
>
> (ref a, b) { a = (cast(typeof(a)) (a + b); }(
>   e1,
>   (ref a) { auto x = a; ++a; return x; }(e2)
> )
>
> whereas lowering of e1 += ++e2 is:
>
> e1 += ++e2
>
> -\>
>
> (ref a, b) { a = (cast(typeof(a)) (a + b); }(
>   e1,
>   (ref a) { ++a; return a; }(e2)
> )
>
>
> Andrei

Fixed in SDC.


More information about the Digitalmars-d mailing list