postincrement behaviour (differences between dmd and gdc)

Daniel Gibson metalcaedes at gmail.com
Wed Apr 20 04:28:06 PDT 2011


Am 20.04.2011 12:58, schrieb bearophile:
> Iain Buclaw:
>
>> Skipping all undefined behaviour/which one is correct talk, an alternative
>> suggestion would be to treat such nonsensical code as an error - like "Cannot
>> modify the value of a variable twice in the same expression." - as this kind
>> of thing I would expect to be almost always a bug.
>
> Thank you for raising this topic again. In my opinion in a modern language, even a system language, this kind of undefined (and different across different compilers) is _not_ acceptable.
> Another source of some undefined behaviours are function calls.
>

I think the DMD way is conformant with the D2 specification, see 
http://digitalmars.com/d/2.0/operatoroverloading.html
"e++ [is rewritten as] (auto t=e, ++e, t)", so x=x++; shouldn't change 
the value of x. (Yeah, this is for overloading, but the operator should 
behave the same for simple types).

Of course x = x++; still makes no sense and should probably cause a 
warning or an error.

> Two possible solutions for D:
> - Turn such situations that lead to undefined behaviour into syntax errors;
> - Do define and standardize such behaviours, even if this may cause tiny performance losses on some CPUs.
>
> Bye,
> bearophile

Cheers,
- Daniel


More information about the Digitalmars-d mailing list