Order of evaluation

来自cppreference.com

 
 
C語言編寫
大會的主題
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
預處理器
評論
關鍵字
ASCII表
轉義序列
C
流量控制
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
條件執行語句
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
迭代語句
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
跳轉語句
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
功能
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
函數聲明
的歷史。內嵌說明
類型
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
規範
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV符
存儲類說明
alignas說明 (C99)
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
表達式
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
為了評價
其他運營商
運營商
運算符的優先順序
實用工具
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
屬性 (C99)
轉換
雜項
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
內聯彙編
 
評價任何C運算符,包括評價函數的參數在函數調用表達式的順序,並在任何表達式中的子表達式的計算順序的操作數的順序是不確定的(除非特別註明,以下)。編譯器將對其進行評估,以任何順序,相同的表達式時,可以選擇另一種秩序再次被評為.
Original:
Order of evaluation of the operands of any C operator, including the order of evaluation of function arguments in a function-call expression, and the order of evaluation of the subexpressions within any expression is unspecified (except where noted below). The compiler will evaluate them in any order, and may choose another order when the same expression is evaluated again.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
的概念不存在左向右或由右至左的評價C,這是不被混淆與左到右,右到左的運營商之間的關聯性的表達a + b + c被解析為(a + b) + c由於在運行時,左到右運營商+之間的關聯性進行評估,但該子表達式c第一(或最後一個,或在同一時間ab).
Original:
There is no concept of left-to-right or right-to-left evaluation in C, which is not to be confused with left-to-right and right-to-left associativity of operators: the expression a + b + c is parsed as (a + b) + c due to left-to-right associativity of operator+, but the subexpression c may be evaluated first (or last, or at the same time as a or b) at run time.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目錄

[编辑] 定義

[编辑] 評估

有兩種類型的評價由編譯器執行的每個表達式或子表達式(這兩者都是可選的):
Original:
There are two kinds of evaluations performed by the compiler for each expression or subexpression (both of which are optional):
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 「數值計算」表達式返回的值來計算的。這可能涉及的對象的身份(左值評價)測定或讀取先前分配到一個對象(右值評價)的值的
    Original:
    value computation: calculation of the value that is returned by the expression. This may involve determination of the identity of the object (lvalue evaluation) or reading the value previously assigned to an object (rvalue evaluation)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 「副作用」:揮發性glvalue,修改(寫)到指定的對象,修改文件,修改的浮點環境(如果支持的話),或者調用一個函數,對象的訪問(讀或寫)做任何操作.
    Original:
    side effect: access (read or write) to an object designated by a volatile glvalue, modification (writing) to an object, modifying a file, modifying the floating-point environment (if supported), or calling a function that does any of those operations.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
如果沒有副作用,是由一個表達式,編譯器可以判斷的價值不使用,該表達式評估.
Original:
If no side effects are produced by an expression and the compiler can determine that the value is not used, the expression is not evaluated.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 訂購

「測序之前」是一個非對稱的,傳遞的,對在同一個線程(如果涉及原子類型和記憶障礙,它可能會延長跨線程)的評價之間的關係.
Original:
"sequenced-before" is an asymmetric, transitive, pair-wise relationship between evaluations within the same thread (it may extend across threads if atomic types and memory barriers are involved).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 如果一個序列點之間存在的子表達式E1和E2,E1的值的計算和副作用測序前的每一個值的計算和副作用的E2
    Original:
    If a sequence point is present between the subexpressions E1 and E2, then both value computation and side effects of E1 are sequenced before every value computation and side effect of E2
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 如果評價一個前評價B測序,然後將評價一個完整的評價的B開始之前。 (C11 起)
    Original:
    If evaluation A is sequenced before evaluation B, then evaluation of A will be complete before evaluation of B begins. (C11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 如果A前B和B的前一個測序測序,然後評價的B是A開始之前完成評估。 (C11 起)
    Original:
    If A is not sequenced before B and B is sequenced before A, then evaluation of B will be complete before evaluation of A begins. (C11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 如果A沒有B和B測序之前不測序A之前,則有兩種可能性存在:(C11 起)
    Original:
    If A is not sequenced before B and B is not sequenced before A, then two possibilities exist: (C11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • *編序的A和B的評價:他們可能會以任何順序進行,並可能會重疊(在一個線程中執行,編譯器可能會交織的CPU指令,包括A和B)
    Original:
    * evaluations of A and B are unsequenced: they may be performed in any order and may overlap (within a single thread of execution, the compiler may interleave the CPU instructions that comprise A and B)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • * A和B的評價是不能決定排序:它們可能以任何順序進行,但不能重疊:無論是A在B之前完成,或B之前完成A.可能是相反的順序下一次相同表達式求值.
    Original:
    * evaluations of A and B are indeterminably-sequenced: they may be performed in any order but may not overlap: either A will be complete before B, or B will be complete before A. The order may be the opposite the next time the same expression is evaluated.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 規則

1)
有一個序列點後的評價函數的所有參數和功能代號,和實際的函數調用前.
Original:
There is a sequence point after the evaluation of all function arguments and of the function designator, and before the actual function call.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
任何運算符的操作數的值計算(但不是副作用)測序之前的操作的結果(而不是其副作用)的值計算。 (C11 起)
Original:
The value computations (but not the side-effects) of the operands to any operator are sequenced before the value computation of the result of the operator (but not its side-effects). (C11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
有一個序列點後的第一個(左)操作的評估和評價以下二元運算符的第二個(右)操作前:&&(邏輯與),||(邏輯或),和,(逗號).
Original:
There is a sequence point after evaluation of the first (left) operand and before evaluation of the second (right) operand of the following binary operators: && (logical AND), || (logical OR), and , (comma).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
有一個序列點後的第一個(左)操作的評估,評估前的第二個或第三個操作數(以較早者為準計算)條件運算符?:
Original:
There is a sequence point after evaluation of the first (left) operand and before evaluation of the second or third operand (whichever is evaluated) of the conditional operator ?:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
副作用(左參數的修改)的直接賦值操作符和複合賦值操作符的所有測序後,左,右參數的值計算(但不包括副作用)。 (C11 起)
Original:
The side effect (modification of the left argument) of the direct assignment operator and of all compound assignment operators is sequenced after the value computation (but not the side effects) of both left and right arguments. (C11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
測序的的遞增後和postdecrement運營商的值計算之前,它的副作用。 (C11 起)
Original:
The value computation of the postincrement and postdecrement operators is sequenced before its side-effect. (C11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
是在一個完整的說明符的結束點的序列。 (C99 起)
Original:
There is a sequence point at the end of a full declarator. (C99 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
有一個序列點後評價一個完整的表達式(表達式,它是不是一個子表達式:典型的結束與一個的分號或一個控制語句如果/開關/而/)和先下一充分體現.
Original:
There is a sequence point after the evaluation of a full expression (an expression that is not a subexpression: typically something that ends with a semicolon or a controlling statement of if/switch/while/do) and before the next full expression.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
9)
有一個序列點之前返回庫函數。 (C99 起)
Original:
There is a sequence point immediately before the return of a library function. (C99 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
10)
有一個序列點後的行動與每個轉換說明符格式化I / O (C99 起)
Original:
There is a sequence point after the action associated with each conversion specifier in formatted I/O. (C99 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
11)
有序列點之前和之後每個調用的庫函數qsortbsearch之間,以及在任何呼叫的比較功能和相關聯的對象的運動由qsort(C99 起)由一個比較函數
Original:
There are sequence points before and immediately after each call to a comparison function made by the library functions qsort and bsearch, as well as between any call to the comparison function and the movement of the associated objects made by qsort (C99 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
12)
不定測序,測序前或後測序另一個函數調用一個函數調用(CPU指令不能交錯,構成不同的函數調用的功能,即使是內聯)(C11 起)
Original:
A function call that is not sequenced before or sequenced after another function call is indeterminately sequenced (CPU instructions that constitute different function calls cannot be interleaved, even if the functions are inlined) (C11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
13)
在初始化列表表達式中,所有的評估都猶豫不決測序(C11 起)
Original:
In initialization list expressions, all evaluations are indeterminately sequenced (C11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
14)
對於不定排序的函數調用,操作的複合賦值操作符,前綴和後綴形式的遞增和遞減運算是單一的評價。 (C11 起)
Original:
With respect to an indeterminately-sequenced function call, the operation of compound assignment operators, and both prefix and postfix forms of increment and decrement operators are single evaluations. (C11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 未定義的行為

1)
如果一個副作用,在標量對象的編序相對於在同一個標​​量對象的另一種副作用,該行為是未定義.
Original:
If a side effect on a scalar object is unsequenced relative to another side effect on the same scalar object, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

i = ++i + i++; // undefined behavior
i = i++ + 1; // undefined behavior
f(++i, ++i); // undefined behavior
f(i = -1, i = -1); // undefined behavior

2)
如果一個副作用,在標量對象的編序的相對值,使用相同的標量對象的值的計算,該行為是未定義.
Original:
If a side effect on a scalar object is unsequenced relative to a value computation using the value of the same scalar object, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

f(i, i++); // undefined behavior
a[i] = i++; // undefined bevahior

3)
上述規則中的至少一個允許的子表達式的順序允許這種非循序副作用只要適用.
Original:
The above rules apply as long as at least one allowable ordering of subexpressions permits such an unsequenced side-effect.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 另請參閱

運算符優先順序表達式定義了如何構建自己的源代碼表示.
Original:
運算符優先順序 which defines how expressions are built from their source code representation.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.