Greetings!
Another question to the language subtleties.
As I have understood until this point (also thanks to another thread I posted here a long time ago), operator precedence has nothing to do with order of evaluation. In my textbook, the following is given as an example for undefined behavior:
1 2
|
int i = 0;
a[i] = i++; // assume the array exists
|
My reasoning:
[ ] and ++ have higher precedence than =, so it is clear that the expression can be understood as (a[i]) = (i++).
The = operator works as follows.
1. The return value of the expressions on both sides is computed. The return value of a[i] is a reference to the array element stored at a[0]. The return value of i++ is 0.
2. The return value of the right-hand side is written into a[i].
3. A reference to a[i] is returned as the value of the = expression.
The problem is that the side effect of i++ can be applied either between 1. and 2., between 2. and 3., or after 3. In other words, I don't know whether 0 was written to a[0] or a[1], and I don't know whether the return value of = gives a[0] or a[1].
Is this correct?