I recently wanted to get a better feeling for the return values of the ++i and the i++ operator. So I created this small program here:
#include <iostream>
using namespace std;
int main()
{
int i = 0;
int j = 0;
cout << "i++ " << i++ << " i " << i << endl;
cout << "++j " << ++j << " j " << j << endl;
}
Now looking at the code I would expect that when I execute it I get the following result:
i++ 0 i 1
++j 1 j 1
Compiling the above snippet with llvm/clang 3.5 (Apple LLVM version 6.0 (clang-600.0.51)) yields the following warning:
main.cpp:8:23: warning: unsequenced modification and access to 'j'
[-Wunsequenced]
cout << "++j " << ++j << " j " << j << endl;
^ ~
1 warning generated.
What does that mean in this context? The only blog post I found was not so helpful since I can't imagine a reordering of the output somehow. What would the output of such a reordering look like?
There's also a couple of similar questions here. The only good question on the subject I found was this one. But I don't understand how this would create the compiler warning above.
Compiling the code from above with gcc 4.9 (the flag -std=c++11 was enabled) didn't show this warning at all.