22

In the following type of code is there a sequence point between each variable construction, or is the result undefined?

int a = 0;
int b = a++, c = a++;

I wasn't able to find in the standard a specific reference to a sequence point here. Does that mean it is undefined, or just that I failed in my search? The completion of an expression is a sequence point, but does the above initialization also count?

4

2 回答 2

26

我相信由于8[dcl.decl]/3 ,行为是明确定义的

声明中的每个 init-declarator 都被单独分析,就好像它本身在声明中一样。

甚至在脚注中还解释为

具有多个声明符的声明通常等效于相应的声明序列,每个声明都具有单个声明符。那是

T D1, D2, ... Dn;

通常相当于

T D1; T D2; ... T Dn;
于 2011-06-20T16:11:12.687 回答
9

正如您怀疑每个初始化表达式之后都有一个序列点,因为它们是完整的表达式(1.9/16、1.9/12)。

于 2011-06-20T16:07:46.183 回答