Order of evaluation of post-increment operator
    John Colvin via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sun Dec 28 13:08:47 PST 2014
    
    
  
On Sunday, 28 December 2014 at 20:25:59 UTC, bearophile wrote:
> John Colvin:
>
>> I guess there are cases where it's not easily catchable:
>>
>> void foo(int* p0, int* p1)
>> {
>>    (*p0)++ = (*p1)++;
>> }
>>
>> what happens when p0 == p1?
>
> The undefined code can be found statically, the run-time values 
> are irrelevant.
>
> Bye,
> bearophile
It depends what you mean by "undefined". Sure, the order of those 
2 ++ operations is undefined in all cases, but it doesn't lead to 
undefined *behaviour* unless the pointers are the same.
There's loads of code out there that has undefined order of 
operations but is invariant w.r.t. said ordering and is therefore 
correct.
    
    
More information about the Digitalmars-d-learn
mailing list