Evaluation order of "+="

Patrick Schluter via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 11 22:46:58 PDT 2016


On Tuesday, 12 July 2016 at 00:16:58 UTC, deadalnix wrote:
> On Monday, 11 July 2016 at 23:31:40 UTC, Danika wrote:
>> On Monday, 11 July 2016 at 23:04:00 UTC, Johan Engelen wrote:
>>> LDC recently changed the evaluation order of "+=" (I think 
>>> unintentionally, some other eval order problems were fixed). 
>>> Now, it is different from DMD.
>>> I am going to argue that I think DMD's order is more useful 
>>> in the context of fibers, and would like your opinion.
>>
>> I really think it is a bug, in C it prints 10. And following 
>> the flow, you changed the sum to 9 and after that added 1, so 
>> It would be 10.6
>
> In C, it is UB.

A function call is a sequence point in C, so it is not UB. What 
happens here in LDC is probably that the call is inlined and 
therefore losing the sequence point. That is one of the dangers 
of aggressive inlining. The behaviour described by op would be 
definitly a bug in C. For D I don't know as I don't know if the 
sequence point rules are as strictly defined as in C.


More information about the Digitalmars-d mailing list