Evaluation order of index expressions
kinke via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 25 05:38:28 PDT 2015
On Monday, 25 May 2015 at 08:00:15 UTC, Jonathan M Davis wrote:
> It might be completely well-defined and consistent, but it may
> not be what you expect, and even if it is, a slight change to
> the code could change the order.
If the behavior isn't what I expect (and I don't think that's
often case for left-to-right order), then the language should
force me to express the intention differently. If it's not
well-defined, I may not be aware of such issues until I use a
different compiler. Allowing implementation-dependent evaluation
order is just begging for additional bugs and portability issues.
Another example:
b = 0;
((++b *= 5) *= 2) += ++b * (b -= 6);
DMD yields b=60, LDC the intuitively correct b=65. If it's well
defined, one may argue about the form of such a statement, but
it's not silly code with different results depending on the used
D compiler anymore.
+1 for Timon's PR being merged asap.
More information about the Digitalmars-d
mailing list