P
Peter
Section 1.9 ("Program execution") of C++11 standard introduces the following example of undefined behaviour:
for function declared as
void f(int, int);
the call:
f(i = -1, i = -1);
yields undefined behaviour.
How come? Of course I know the order in which arguments of f are evaluated is unspecified, so result of f(i, i++) would indeed be undefined, but what's wrong with f(i = -1, i = -1)? Why should the order matter here? f doesn't get called until both arguments are evaluated and both assignment expressions are independent, so what difference does it make if first and then second gets evaluated or the other way round since both evaluate to -1 anyway?
for function declared as
void f(int, int);
the call:
f(i = -1, i = -1);
yields undefined behaviour.
How come? Of course I know the order in which arguments of f are evaluated is unspecified, so result of f(i, i++) would indeed be undefined, but what's wrong with f(i = -1, i = -1)? Why should the order matter here? f doesn't get called until both arguments are evaluated and both assignment expressions are independent, so what difference does it make if first and then second gets evaluated or the other way round since both evaluate to -1 anyway?