Evaluation order of index expressions
kinke via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 25 12:02:01 PDT 2015
On Monday, 25 May 2015 at 17:21:05 UTC, Johannes Pfau wrote:
> import std.stdio;
> void main()
> {
> int a = 0;
> int bar()
> {
> a++;
> return a;
> }
> a += bar(); // => a = a + bar()
> writeln(a);
> }
>
> DMD: 2
> GDC: 1
>
> which one is correct?
So what about my previous example?
int b = 0;
((++b *= 5) *= 2) += ++b * (b -= 6);
DMD 2.067.1: 60, latest LDC: 65, GDC: ?
This divergence probably doesn't have anything to do with the
evaluation order, which seems to be identical (LTR), but rather
how the lhs expression is treated (a double-nature as nested
lvalue to be assigned to and rvalue result of a binAssign
expression). For more context, see
https://github.com/ldc-developers/ldc/pull/873.
More information about the Digitalmars-d
mailing list