问题
Possible Duplicate:
Is the comma in a variable list a sequence point?
If I have the following code does the comma act as a normal sequence point, or is the behaviour undefined?
int i = 1, j = i;
I don't actually plan to use this (our internal standard prohibits even int i, j
) but I was curious and it prooved oddly tricky to google.
回答1:
It's well-defined:
8. Declarators: [dcl.decl]
3) Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself.
And the note:
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.
For completness (because the note says usually):
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`
来源:https://stackoverflow.com/questions/12729962/is-the-order-of-assignment-in-a-list-of-initialized-variables-undefined