G
Yes, I do think it has undefined behaviour.Gordon said:Do you think this expression causes undefined behavior:
x = x = 11;
?
In this situation, I think it can, since there is no sequence point
and the two side effects on the same variable can occur SIMULTANEOUSLY.
That the two side effects are storing the same value is not relevant.
And rather than
x=(x=5,11);
Consider x=11; x^=(x=5,11);
Obviously this has undefined behaviour.
While it seems a bit bizarre, I know of nothing in the standard that
would prohibit a hardware implementation that needs to read a value
before storing a new value (an example might be hardware that can only
flip bits, not set/reset them) and so I expect this undefined behaviour
to extend to things like x=x=11; and x=(x=5,11);
And on this hardware, x=(x=5,11) wouldn't leave x=5 or x=11, it would
leave x with some undefined value.
This would also mean things like g=f(); where g is global and f()
modifies g would also have undefined behaviour.
Tim.