c之表达式的右手边总是先求值
右侧是否总是评估在左侧之前?然后右侧的结果将传递到左侧。我不是在谈论诸如 A[i]=i++
之类的异常
我说的是正常情况:
A[i] = (j+32+43 & K);
A[j] != (A[j] + A[k]);
会先评估所有这些表达式的右侧部分,然后将结果与左侧进行比较吗? (总是)
请您参考如下方法:
一般来说,子表达式的计算顺序是不确定的,有一些异常(exception),例如逻辑与、逻辑或、逗号运算符等......
由于您 comment 表示您对一般规则感兴趣:
any operstor @YuHao if there is any general rule
这将由 draft C99 standard 部分
6.5
Expressions 段落
3
涵盖(强调我的 future ):
The grouping of operators and operands is indicated by the syntax.74) Except as specified later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation of subexpressions and the order in which side effects take place are both unspecified.
这在 draft C11 standard 中基本相同,但 C11 未列出异常,因此引用 C99 更方便。 C11 中的段落
3
说:
The grouping of operators and operands is indicated by the syntax.85) Except as specified later, side effects and value computations of subexpressions are unsequenced.86)
专门针对赋值运算符 C99 说:
The order of evaluation of the operands is unspecified [...]
C11 说:
[...] The evaluations of the operands are unsequenced.
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。