Wait, isn't this an undefined behavior? Is the order of evaluations of `x` in the left side and `x++` in the right side defined? I'm always confused at things like this!
Wait, isn't this an undefined behavior? Is the order of evaluations of `x` in the left side and `x++` in the right side defined? I'm always confused at things like this!
But, well, the specs are another matter entirely.
x++ returns x and then increments it, so yes the spec agrees with your intuition here.
Whereas ++x increments x and then returns the incremented x.
That subtle difference between x++ and ++x has been the debugging nightmare of many a C developer over the years. It's also why there's a fun irony in the C++ name and why people say the actual successor to C will be ++C.
I was talking about my statement at the upper comment. I used x++ there, not ++x. The doubt is about the value of the other x.
The difference you talk is about the main behavior of the operators. You won't find any description of them that does not state it.
My apologies for answering the wrong question, but yes in that case the standard is also mostly clear that you can assume that things are evaluated from left to right in C/C++ and thus the first x in the line should be evaluated prior to the x++ later in the line...
Every compiler seems to act the same way today, but some specs oriented optimizer might play havoc with that line.