yohhoyの日記

2012-03-04

C/C++関数引数の評価順序

プログラミング言語C/C++では、関数実引数の評価順序は未規定(unspecified)となっている。標準規格における言及箇所のメモ。

C99

JTC1/SC22/WG14 N1256 6.5.2.2/p10より引用。

10 The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspecified, but there is a sequence point before the actual call.


C11

JTC1/SC22/WG14 N1570 6.5.2.2/p10より引用。

10 There is a sequence point after the evaluations of the function designator and the actual arguments but before the actual call. Every evaluation in the calling function (including other function calls) that is not otherwise specifically sequenced before or after the execution of the body of the called function is indeterminately sequenced with respect to the execution of the called function.94)
脚注94) In other words, function executions do not "interleave" with each other.


C++11

JTC1/SC22/WG21 N3337 5.2.2/p4, p8, 1.9/p13から関連箇所を引用。

4 When a function is called, each parameter (8.3.5) shall be initialized (8.5, 12.8, 12.1) with its corresponding argument. [Note: Such initializations are indeterminately sequenced with respect to each other (1.9) -- end note]
8 [Note: The evaluations of the postfix expression and of the argument expressions are all unsequenced relative to one another. All side effects of argument expression evaluations are sequenced before the function is entered (see 1.9). -- end note]

13 (snip) Evaluations A and B are indeterminately sequenced when either A is sequenced before B or B is sequenced before A, but it is unspecified which. [Note: Indeterminately sequenced evaluations cannot overlap, but either could be executed first. -- end note]

スパム対策のためのダミーです。もし見えても何も入力しないでください
ゲスト


画像認証

トラックバック - http://d.hatena.ne.jp/yohhoy/20120304/p1