I’m still slightly confused after reading this topic. Is the following C++ expression *d++ = ~(*d); well defined? Yes, I know compound expressions like this are ugly.. I didn’t write it.
I see a slight difference in the generated assembly when I compare it to:
*d = ~(*d);
d++;
Assembly:
*d++ = ~(*d);
0x83384 LDR R3,[R0 <d>,4] <<diff
0x83388 ADD R1 <c>, R1 <c>, 1
0x8338c MVN R3, R3
0x83390 STR R3,[R0 <d>],4
vs
*d = ~(*d);
d++;
0x83384 LDR R3,[R0 <d>]
0x83388 ADD R1 <c>, R1 <c>, 1
0x8338c MVN R3, R3
0x83390 STR R3,[R0 <d>],4
Thanks!
In this expression no object is having a new value stored to it more that once. The value of
d + 1is stored todas a side effect of the incremement operator (d++) and the value of the object pointed to bydbefore this increment is written to by the assignment operator.The issue is that
dis read, not merely to determine the value to be written back to it (i.e.d + 1) but is also read to determine the address to read from in the right hand side sub-expression~(*d).This violates the third sentence of ISO/IEC 14882:2003 5 [expr] / 4 (first sentence omitted for brevity):