Order of evaluation of a += a++;

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 4 21:50:02 PDT 2015


On 4/4/15 7:54 PM, deadalnix wrote:
> 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.

Awesome, thanks! -- Andrei


More information about the Digitalmars-d mailing list