Possible Duplicate:
Undefined Behavior and Sequence Points
I wrote the following code and [to my surprise] it printed: xx: 1 zz: 0
I would have expected both xx and zz to print as 0. This is tried with gcc 4.2, 4.4 and 4.7 on linux and darwin. Upon some research, I find that x=x++ is undefined behavior but I would expect (x++) to be executed first and return 0. Can someone shed light into this strange compiler behavior?
#include <iostream>
using namespace std;
int frwd(int aa) { return aa; }
int main() {
int xx = 0;
xx = (xx++);
cout << "xx:" << xx << endl;
int zz = 0;
zz = frwd(zz++);
cout << "zz:" << zz << endl;
}