Skip to content

Commit

Permalink
Merge pull request #6 from jkm/master
Browse files Browse the repository at this point in the history
Evaluation order of function arguments
  • Loading branch information
andralex committed Oct 12, 2012
2 parents dbc9e61 + 262eea5 commit deb29c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 15 additions & 1 deletion expression.dd
Expand Up @@ -58,14 +58,28 @@ $(V1
-------------
i = i++;
c = a + (a = b);
func(++i, ++i);
-------------
$(P If the compiler can determine that the result of an expression
is illegally dependent on the order of evaluation, it can issue
an error (but is not required to). The ability to detect these kinds
of errors is a quality of implementation issue.
)

$(P The evaluation order of function arguments is defined to be left to
right. This is similar to Java but different to C/C++ where the evaluation
order is unspecified. Thus, the following code is valid and well defined.
)
-------------
import std.conv;
int i = 0;
assert(text(++i, ++i) == "12"); // left to right evaluation of arguments
-------------

$(P But even though the order of evaluation is well defined writing code that
depends on it is rarely recommended.
$(B Note that dmd currently does not comply with left to right evaluation of
function arguments.))

<h2><a name="Expression">Expressions</a></h2>

$(GRAMMAR
Expand Down
5 changes: 0 additions & 5 deletions portability.dd
Expand Up @@ -31,11 +31,6 @@ a + b + c
control order of evaluation.
)

$(P Function parameters can be evaluated either left to right
or right to left, depending on the particular calling conventions
used.
)

$(P If the operands of an associative operator + or * are floating
point values, the expression is not reordered.
)
Expand Down

0 comments on commit deb29c6

Please sign in to comment.