Order of evaluation for named arguments
Steven Schveighoffer
schveiguy at gmail.com
Sat Mar 29 18:38:31 UTC 2025
In the D spec, the function parameter [section on order of
evaluation](https://dlang.org/spec/expression.html#order-calls)
says:
> Arguments are evaluated left to right.
So a question was raised, what about named arguments, since those
might not match the order of parameters?
I decided to test:
```d
import std.stdio;
void foo(int a, int b) {
writeln(i"a: $(a), b: $(b)");
}
void main() {
int x;
foo(b: ++x, a: ++x);
}
```
According to the spec, this should print "a: 2, b: 1", as the
order of evaluation of the expression should go left to right.
But the actual printout is "a: 1, b: 2".
So the question is, should we modify the spec to reflect this, or
would it be better to change the compiler to enforce this
left-to-right evaluation rule?
-Steve
More information about the Digitalmars-d
mailing list