Let\'s just take for example the specific compound assignment operator ^=
. This stackoverflow page says modification of the left operand may have not been done
You link to a C question. However, this is irrelevant as C and C++ are different languages.
Also, sequence points no longer exist as of C11 and C++11; instead the relations sequenced before, unsequenced, and indeterminately sequenced exist.
In that quote:
a
.2 + 2
is 4
, and the value computation is the process of determining that 4
was the value).There are two value computations here: a ^ b
, and a =
(that result).
In the quoted text, for a = a ^ b
, things must occur in this order:
Retrieve values from a
and b
(in either order), and determine the memory location in which to store the result (value computation of right and left operand, respectively)
Store the result in a
(the assignment). The involves value computation of a ^ b
, which isn't mentioned in the quote but clearly the result must be calculated before it is stored
Perform value computation of the assignment expression. This means yielding up the value stored in a
ready for a surrounding expression to use (value computation).
You're right that 2 and 3 seem "backwards" compared to the order you might do things on paper. But remember that in general, y
is different to the value of x = y
. The value of the assignment expression is the same as the value stored in x
. (Example: int x; double y = (x = 6.5);
- then y
is 6
, not 6.5
). So we can do this by storing the result in a
and then offering a
as the result.