<分区>
Possible Duplicate:
Is the comma in a variable list a sequence point?
如果我有以下代码,逗号是作为一个正常的序列点,还是行为未定义?
int i = 1, j = i;
我实际上并不打算使用它(我们的内部标准甚至禁止 int i, j
),但我很好奇并且证明它对 google 来说非常棘手。
<分区>
Possible Duplicate:
Is the comma in a variable list a sequence point?
如果我有以下代码,逗号是作为一个正常的序列点,还是行为未定义?
int i = 1, j = i;
我实际上并不打算使用它(我们的内部标准甚至禁止 int i, j
),但我很好奇并且证明它对 google 来说非常棘手。
最佳答案
定义明确:
3) Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself.
还有注释:
90) A declaration with several declarators is usually equivalent to the corresponding sequence of declarations each with a single declarator. That is
T D1, D2, ... Dn;
is usually equvalent to
T D1; T D2; ... T Dn;
where T is a decl-specifier-seq and each Di is an init-declarator.
为了完整性(因为注释说通常):
The exception occurs when a name introduced by one of the declarators hides a type name used by the dcl-specifiers, so that when the same dcl-specifiers are used in a subsequent declaration, they do not have the same meaning, as in
struct S { ... }; S S, T;
// declare two instances of struct Swhich is not equivalent to
struct S { ... }; S S; S T; // error`
关于c++ - 初始化变量列表中的赋值顺序是否未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12729962/