In C/C++, the second statement in
int i = 0;
int j = i++ + i++ + ++i;
invokes both
- unspecified behavior, because the order of evaluation of operands is unspecified, and
- undefined behavior, because the side effects on the same object
i
are unsequenced relative to each other.
See for example
Now, given that Swift was designed as a safe language, what is the corresponding situation here? Is the result of
var i = 0
let j = i++ + i++ + ++i
well-defined? Can one conclude from the language reference in the
Swift book that j == 4
?