C 序列点C Sequence Points

在连续的“序列点”之间,仅能通过表达式修改一次对象的值。Between consecutive "sequence points" an object's value can be modified only once by an expression. C 语言定义以下序列点:The C language defines the following sequence points:

  • 逻辑“与”运算符 (&&) 的左操作数。Left operand of the logical-AND operator (&&). 完全计算逻辑“与”运算符的左操作数,并在继续之前完成所有副作用。The left operand of the logical-AND operator is completely evaluated and all side effects complete before continuing. 如果左操作数的计算结果为 false (0),则不计算另一个操作数。If the left operand evaluates to false (0), the other operand is not evaluated.

  • 逻辑“或”运算符 (||) 的左操作数。Left operand of the logical-OR operator (||). 完全计算逻辑“或”运算符的左操作数,并在继续之前完成所有副作用。The left operand of the logical-OR operator is completely evaluated and all side effects complete before continuing. 如果左操作数的计算结果为 true(非零),则不计算另一个操作数。If the left operand evaluates to true (nonzero), the other operand is not evaluated.

  • 逗号运算符的左操作数。Left operand of the comma operator. 完全计算逗号运算符的左操作数,并在继续之前完成所有副作用。The left operand of the comma operator is completely evaluated and all side effects complete before continuing. 始终计算逗号运算符的两个操作数。Both operands of the comma operator are always evaluated. 请注意,函数调用中的逗号运算符不保证计算顺序。Note that the comma operator in a function call does not guarantee an order of evaluation.

  • 函数调用运算符。Function-call operator. 计算函数的所有参数,并在输入函数前完成所有副作用。All arguments to a function are evaluated and all side effects complete before entry to the function. 未指定参数之间的计算顺序。No order of evaluation among the arguments is specified.

  • 条件运算符的第一个操作数。First operand of the conditional operator. 完全计算条件运算符的第一个操作数,并在继续之前完成所有副作用。The first operand of the conditional operator is completely evaluated and all side effects complete before continuing.

  • 完全初始化表达式的末尾(即,不是一个表达式的一部分的另一个表达式,如声明语句中的初始化的末尾)。The end of a full initialization expression (that is, an expression that is not part of another expression such as the end of an initialization in a declaration statement).

  • 表达式语句中的表达式。The expression in an expression statement. 表达式语句由可选表达式后跟分号 (;) 组成。Expression statements consist of an optional expression followed by a semicolon (;). 为其副作用计算该表达式,并且此计算后面有一个序列点。The expression is evaluated for its side effects and there is a sequence point following this evaluation.

  • 选择(if 或 switch)语句中的控制表达式。The controlling expression in a selection (if or switch) statement. 完全计算该表达式,并在执行依赖于选择的代码之前完成所有副作用。The expression is completely evaluated and all side effects complete before the code dependent on the selection is executed.

  • while 或 do 语句的控制表达式。The controlling expression of a while or do statement. 完全计算该表达式,并且在执行 while 或 do 循环的下一次迭代中的任何语句执行之前完成所有副作用。The expression is completely evaluated and all side effects complete before any statements in the next iteration of the while or do loop are executed.

  • for 语句的所有三个表达式。Each of the three expressions of a for statement. 完全计算这些表达式,并在执行 for 循环的下一次迭代中的任何语句之前完成所有副作用。The expressions are completely evaluated and all side effects complete before any statements in the next iteration of the for loop are executed.

  • return 语句中的表达式。The expression in a return statement. 完全计算该表达式,并在控制返回调用函数之前完成所有副作用。The expression is completely evaluated and all side effects complete before control returns to the calling function.

另请参阅See Also

表达式计算Expression Evaluation