www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Eval order, bug or design decision?

reply Frank Benoit <keinfarbton googlemail.com> writes:
int[] a1, a2;
// ....

int idx = 0;
a1[idx] = a2[idx++];

In Java this has another result like in D.
Java will evaluate from left to right, D does the increment befor doing 
the assignment, so the copied values go into different fields.

Is this a bug or design decision?
Mar 08 2008
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Frank Benoit" <keinfarbton googlemail.com> wrote in message 
news:fqubu4$2d2e$1 digitalmars.com...
 int[] a1, a2;
 // ....

 int idx = 0;
 a1[idx] = a2[idx++];

 In Java this has another result like in D.
 Java will evaluate from left to right, D does the increment befor doing 
 the assignment, so the copied values go into different fields.

 Is this a bug or design decision?
http://www.digitalmars.com/d/1.0/expression.html Very first section. It's illegal code but it's up to the compiler to detect it or not. I guess you could file a bug about it as "accepts-invalid".
Mar 08 2008
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Frank Benoit wrote:
 int[] a1, a2;
 // ....
 
 int idx = 0;
 a1[idx] = a2[idx++];
 
 In Java this has another result like in D.
 Java will evaluate from left to right, D does the increment befor doing 
 the assignment, so the copied values go into different fields.
 
 Is this a bug or design decision?
Currently order of evaluation dependencies are illegal in D. Did you run across it in some Java code?
Mar 08 2008
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
Walter Bright schrieb:
 Frank Benoit wrote:
 Is this a bug or design decision?
Currently order of evaluation dependencies are illegal in D. Did you run across it in some Java code?
Yes, see 2. + 3. change http://www.dsource.org/projects/dwt-linux/changeset/204%3A8ab2f71515ba My eyes will be more sensible for this patterns now :)
Mar 08 2008
parent Walter Bright <newshound1 digitalmars.com> writes:
Frank Benoit wrote:
 Walter Bright schrieb:
 Currently order of evaluation dependencies are illegal in D. Did you 
 run across it in some Java code?
Yes, see 2. + 3. change http://www.dsource.org/projects/dwt-linux/changeset/204%3A8ab2f71515ba My eyes will be more sensible for this patterns now :)
My old C eyes are pretty sensitive to that, too. But it's also clear that D should move to a defined left-to-right order-of-evaluation semantic.
Mar 08 2008