News for hackers. Stuff that matters.
Re:Is C/C++ worth it? by repsilat on Monday July 23, 2012 @09:37PM (#4283889)
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.

There are no comments on this comment yet.