"The preliminary value shall only be read to determine the stored value." It is clear that the wording is contradictory; why does the purpose for which the meaning is read matter?
The point of this proposal is the imposition of a requirement for which the results depend on which operations.
I will steal examples from the Pascal answer .
It:
i = i + 1;
excellent. i read and written in the same expression without an intermediate point in the sequence, but this is normal because writing cannot occur until the reading is complete. The value that needs to be saved cannot be calculated until the expression i + 1 and its subexpression i have been fully evaluated. (And i + 1 has no side effects that can be delayed until the time of writing.) This dependency imposes a strict order: the reading must be completed before recording begins.
On the other hand, these are:
a[i] = (i=1);
has undefined behavior. The subexpression a[i] reads the value of i , and the subexpression i=1 writes the value of i . But the value that should be written to i by writing does not depend on the score that reads i on the left side, and therefore the order of reading and writing is not defined. "Storage value" - 1 ; reading i in a[i] does not determine this value.
I suspect this confusion is that the 2011 revision of ISO C (available in draft N1570 ) reformulated this section. The standard still has the concept of sequence points, but 6.5p2 now says:
If the side effect of a scalar object is independent of another side effect on the same scalar object or the value of the calculation using the value of the same scalar object, the behavior is undefined. If there are several valid orders of expression subexpression, the behavior is undefined if such an Inconsistent side effect occurs in any of the orders.
And paragraph 1 explicitly states what was implicitly accepted on C99:
The calculation of the values of the operands of the operator is sequenced before calculating the value of the result of the operator.
Section 5.1.2.3, paragraph 2, explains the sequence and sequence after the relationship.
source share