"a[++i] = i" vs "a[i] = ++i"

aldanor i.s.smirnov at gmail.com
Fri Dec 20 15:58:46 PST 2013


On Friday, 20 December 2013 at 23:17:31 UTC, bearophile wrote:

> Right, currently the outcome of that kind of code is not 
> specified in D. So writing it is a error, and the D compiler 
> doesn't warn you. Do not write that kind of code in D.
>
> Walter wants to eventually (but when? Five years from now?) 
> make that code specified, this means all the D compilers will 
> know what that kind of code produce and will all give the same 
> result reliably.
>
> But in my opinion making the code unambiguous and specified for 
> the compiler is not enough. You have also to take in account 
> people that write and read the code, it needs to be unambiguous 
> for them too. For them that kind of code can become tricky, 
> even when you know the rules used by the compiler. So I'd like 
> that kind of D code just to be disallowed, to be an error (and 
> this doesn't break compatibility with C, because equivalent C 
> code is not defined).
I completely agree.

I guess my point is, it would be nice if the compiler (at least) 
fired a warning about this kind of things, kinda of like clang 
does for both statements (and rightly so). It is nigh impossible 
for a D newcomer figure out if this kind of code is valid or not, 
and as you can see from the random example above one might think 
that it is indeed the way to go.


More information about the Digitalmars-d-learn mailing list