6.5 Expressions
...
2 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. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.84)
84) This paragraph renders undefined statement expressions such as i = ++i + 1;
a[i++] = i;
while allowing i = i + 1;
a[i] = i;
C 2011 Online Draft
In the statement
printf("%d %#x",C = A^B,C = A^B);
the expressions C = A^B
have a side effect (assign a new value to C
) and they are unsequenced relative to each other (function arguments are not guaranteed to be evaluated from left to right, right to left, or any other order, and their evaluations may even be interleaved), hence the warning. Even though C
is being assigned the same value both times, the behavior is still undefined.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…