// CS 1621 Fall 2005 // Example of inconsistent / unpredictable expression evaluation in C++ // Run this program in Unixs and then on another platform and see if the // output is the same. Try to figure out why the output is at it is on // Unixs. #include using namespace std; int main() { unsigned int i1 = 0, i2, i3, i4, i5, j, k, m1, m2, m3, m4, m5; j = i1++; k = ++i1; cout << j << " " << k << endl; i5 = i4 = i3 = i2 = i1; m1 = i1++ + i1++ + i1++; m2 = i2++ + ++i2 + i2++; m3 = i3++ + ++i3 + ++i3; m4 = ++i4 + i4++ + ++i4; m5 = ++i5 + ++i5 + ++i5; cout << i1 << " " << m1 << endl; cout << i2 << " " << m2 << endl; cout << i3 << " " << m3 << endl; cout << i4 << " " << m4 << endl; cout << i5 << " " << m5 << endl; int w = 0; cout << w++ << " " << w++ << " " << w++ << endl; w = 0; cout << ++w << " " << ++w << " " << ++w << endl; }