Q: Why does multiple calls to xalloc result in delayed output? When I print the id of a stream in a single expression it prints it backwards. Normally this is what comes out:
std::stringstream ss;

std::cout << ss.xalloc() << '\n';
std::cout << ss.xalloc() << '\n';
std::cout << ss.xalloc();

Output is:

4
  5
  6

But when I do it in one expression it prints backwards, why?
std::stringstream ss;

std::cout << ss.xalloc() << '\n'
          << ss.xalloc() << '\n'
          << ss.xalloc();

Output:

6
  5
  4

I know the order of evaluation is unspecified but then why does the following always result in the correct order:
std::cout << 4 << 5 << 6;

Can someone explain why xalloc behaves differently? Thanks.

A: This isn't related to xalloc; any other function that returns a different value each time it's called would do the same thing. The order of evaluation of the arguments is unspecified; the compiler can make the three function calls in any order. Once all the arguments have been evaluated, the order of insertion is from left to right.
