@RyuZUSUNC 艹哈哈哈哈哈哈哈哈哈
论注释的重要性.jpg

@RyuZUSUNC

x = x + 1;

C 中的表达式除了求值以外,还要产生副作用(side effects)。
赋值运算符 = 的语义有两个方面,求值的方面是:返回(yield)右侧运算对象的值(下面写的是左侧,说的是赋值之后的值,不要在意细节(雾)),副作用的方面是:将左侧运算对象产生的左值表示的对象储存的值更新为右侧运算对象产生的值。
副作用的发生要后于两侧运算对象的求值,两侧运算对象求值的顺序未定义。

C11 draft(N1570) 6.5.16 Semantics cluse 3
An
assignment expression has the value of the left operand after the assignment
The side effect of updating the stored value of the left operand is
sequenced after the value computations of the left and right operands. The evaluations of
the operands are unsequenced.

这么看 x=x+1 是赋值表达式(assignment expression)而不是公式(formula)

Sign in to participate in the conversation
小森林

每个人都有属于自己的一片森林,也许我们从来不曾走过,但它一直在那里,总会在那里。迷失的人迷失了,相逢的人会再相逢。愿这里,成为属于你的小森林。