3 ms·
Evaluation order is implementation-defined. I'm pretty sure all of the arguments are evaluated before any printing is done at all. The code cout << "asdf:" <
by repsilat 14y ago
Evaluation order is implementation-defined. I'm pretty sure all of the arguments are evaluated before any printing is done at all. The code
cout << "asdf:" << b()
is equivalent to
(cout << "asdf:") << b()
, which is equivalent to
cout.operator<<("asdf:").operator<<(b())
`b()` can certainly be evaluated before the first `operator<<` is evaluated. Hell, `b()` can be evaluated before "asdf;" is evaluated. Consider the following code:
int f() {
static int a=0;
return a++;
}
cout << f() << " " << f() << endl;
This prints "0 1" in Clang (at all levels of optimisation), and it prints out "1 0" in gcc (again, at all levels of optimisation). If they're differing on something as simple as this it's clearly allowable by the standard.