c++ - 初始化变量列表中的赋值顺序是否未定义?

标签 c++ operator-precedence

<分区>

Possible Duplicate:
Is the comma in a variable list a sequence point?

如果我有以下代码,逗号是作为一个正常的序列点,还是行为未定义?

int i = 1, j = i;

我实际上并不打算使用它(我们的内部标准甚至禁止 int i, j),但我很好奇并且证明它对 google 来说非常棘手。

最佳答案

定义明确:

8.声明符:[dcl.decl]

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 tostruct S { ... }; S S; S T; // error`

关于c++ - 初始化变量列表中的赋值顺序是否未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12729962/

相关文章:

c++ - 从控制台获取字符串但不知道长度

c++ - 数字滤波器和 std::inner_product 优化

perl - 在列表上下文中分配散列时有什么区别?

mysql - MySql not 运算符的令人惊讶的行为

mysql - 为什么涉及用户变量的表达式的求值顺序未定义?

c++ - 如何在 OSX 10.9 上的 GDB 中打印 C++ vector 的元素?

c++ - 如何通过首先检查它们是否用 New() 初始化来删除 vtk 对象?

c++ - 使用继承时类的大小是多少?

c++ - C++ 中括号和逗号表达式中类型的计算顺序 (x0 = y0, x1 = y1, x2 = x0, ...)

mysql - Laravel 多个 WHERE() 运算符优先级