Skip to content

Evaluation order of function arguments #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion expression.dd
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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