You seem to be implying that the behavior will definitely be that of one of the possible orderings, but that's not the case. It's just not unspecified, which increment happens first - the behavior is completely undefined. As far as the standard is concerned, the code may print "23 42" or even crash.
...
Speaking of function calls, I need to correct my earlier answer: The fact that the built-in << operator does not introduce a sequence point is irrelevant because here we're using an overloaded << operator and overloaded operators behave like function calls.
Yes.
Because an int
is a scalar.
If a
was an object of a user defined type (with increment operators),std::cout << ++a << ' ' << a++ ;
would not result in UB; it is still bad because the evaluations of ++a
and a++
would be 'indeterminately sequenced'
...
C++11 version just change the language that expresses the rules (which is definitely clearer)?
C++11 does make the rules clearer. The canonical pedantic (unclear in C++98) example being:int k = ( f(), g() ) + h() ;
Sequence-point rules had to be discarded and replaced by sequenced-before rules because C++11 is thread and concurrency aware, while C++98 was not. The new rules allow implementations to generate extremely efficient code and at the same time precisely specify the behaviour of the abstract machine.