View previous topic :: View next topic |
Author |
Message |
phoenix
Joined: 06 Mar 2005 Posts: 68
|
Posted: Sat Apr 14, 2007 7:45 am Post subject: Java & D function evaluation order |
|
|
Hi. While working on JDT code, I've encountered an interesting piece of code that I wonder if Tioport handles correctly (not that I'm using TioPort):
Code: | System.arraycopy(this.children, 0, this.children = new ILangElement[length + 1], 0, length); |
This works in Java because the order of evaluation in function calls is well defined (left to right) AND because the arguments are bound to parameters as they are evaluated (and not after all are evaluated).
In D this behavior is unspecified ( http://www.digitalmars.com/d/expression.html , Evaluation Order), even tough DMD seems to follow a Java-like behavior. (haven't tried gdc) _________________ Bruno Medeiros |
|
Back to top |
|
|
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Sun Apr 15, 2007 4:47 am Post subject: |
|
|
This is a problem i also have noticed. TioPort also has special code to handle such things.
http://dsource.org/projects/tioport/wiki/EvalOrder
But I was not aware of the case of eval order in method calls
Actually TioPort handles the bitwise or/and/xor operations.
How can your example call be rewritten in D to work? Is it possible without temporary variables?
I will need to add this functionality for method calls to TioPort. |
|
Back to top |
|
|
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Sun Apr 15, 2007 5:15 am Post subject: |
|
|
With temporary variables this can be refactored to:
Code: |
Type tempvar1 = void;
Type tempvar2 = void;
int tempvar3 = void;
( tempvar1 = this.children, tempvar2 = this.children = new ILangElement[length + 1], tempvar3 = length, System.arraycopy(tempvar1, 0, tempvar2, 0, tempvar3));
|
|
|
Back to top |
|
|
phoenix
Joined: 06 Mar 2005 Posts: 68
|
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Thu Apr 26, 2007 6:58 am Post subject: |
|
|
FYI, this is the corresponding WebNews link. |
|
Back to top |
|
|
|