I'm looking at the final draft of C17, N2176. Here, I'm concerned with what kind of expression with side effects would have it's behaviour undefined.
In section 6.5 Expressions of the standard, there is paragraph 2 that starts with:
If a side effect on a scalar object is unsequenced relative to either
a different side effect on the same scalar object or a value
computation using the value of the same scalar object, the behavior is
undefined.
As I understand it, evaluation of expression x=1 would both produce a value and also initiate a side effect changing the value of object designated by x. The determining factor would than be whether the side effect is sequenced in any way in relation to the value computation that uses the value of object designated by x.
The description in section 6.5.16 Assignment operators contains this sentence:
The side effect of updating the stored value of the left operand is
sequenced after the value computations of the left and right operands.
That does not resolve sequencing of value computation of the whole assignment and the side effect of the assignment.
Also, another sentence:
An assignment expression has the value of the left operand after the
assignment, but is not an lvalue.
Specifies what the final value should be, but does not mandate any sequencing. And I don't see any other text mentioning sequencing regarding side effect and value.
I know that when written as a full statement x=1; the value of assignment is not used. However, the standard says that the value is discarded. That means that it is as if first the value was evaluated and later discarded, so the undefined behaviour should still be triggered.
Is there any other part of the standard that makes this statement behaviour not undefined?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…