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

Timon Gehr timon.gehr at gmx.ch
Tue Dec 24 07:54:12 PST 2013


On 12/24/2013 02:37 PM, monarch_dodra wrote:
> On Tuesday, 24 December 2013 at 07:08:49 UTC, David Held wrote:
>> Ok, let's make it more interesting...
>
> The compiler is only supposed to error out on stuff that is actually
> illegal according to the language.
>
> What you are doing is not *illegal*, it just produces un-specified
> behavior.  ...

The behaviour is specified modulo evaluation order. An implementation 
will just pick some evaluation order, it is not allowed to produce 
arbitrary behaviour. In any case, it is a given that strict 
left-to-right evaluation order will eventually be required, so I don't 
think that it makes a lot of sense to discuss whether or not to error out.


More information about the Digitalmars-d-learn mailing list