J
Jim Hester
The following stemmed from a slightly bizarre line in a student's work that
surprised my by doing what HE wanted it to do. Question: Are the second and
third cases below correct by some interpretation of the language semantics
that I'm missing, or is it some kind of register-optimization bug (or
something else)?
int i = 1;
int j;
j = i++; // i ends up 2, j ends up 1 (as expected)
cout << "i=1; j = i++; i == " << i << " j == " << j << endl << endl;
int k = 1;
k = k++; // k ends up 2 - not exptectd.
cout << "K=1; k = k++; k == " << k << endl << endl;
int m = 1;
int p;
m = ( p = m++ ); // p ends up 1 as expected, but m remains 2 (not set back
to 1)
cout << "m=1; m = (p = m++); p == " << p << " m == " << m << endl << endl;
surprised my by doing what HE wanted it to do. Question: Are the second and
third cases below correct by some interpretation of the language semantics
that I'm missing, or is it some kind of register-optimization bug (or
something else)?
int i = 1;
int j;
j = i++; // i ends up 2, j ends up 1 (as expected)
cout << "i=1; j = i++; i == " << i << " j == " << j << endl << endl;
int k = 1;
k = k++; // k ends up 2 - not exptectd.
cout << "K=1; k = k++; k == " << k << endl << endl;
int m = 1;
int p;
m = ( p = m++ ); // p ends up 1 as expected, but m remains 2 (not set back
to 1)
cout << "m=1; m = (p = m++); p == " << p << " m == " << m << endl << endl;