Is the assignment order in the list of initialized variables undefined?

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

If I have the following code, does the comma act like a normal point in the sequence, or is this behavior undefined?

int i = 1, j = i; 

In fact, I do not plan to use this (our internal standard forbids even int i, j ), but I was curious, and it was very strange for google.

+4
source share
1 answer

It is clearly defined:

8. Declarators: [dcl.decl]

3) Each initialization declarator in the declaration is analyzed separately, as if it were in the declaration on its own.

And note:

90) A declaration with several declarators is usually equivalent to the corresponding sequence of declarations, each with one descriptor. it

T D1, D2, ... Dn;

usually equivalent

T D1; T D2; ... T Dn;

where T is the decl-seq specifier, and each Di is an INIT descriptor.

For completeness (because the note is usually written):

An exception occurs when the name entered by one of the declarators hides the type name used by dcl specifiers, so when the same dcl specifiers are used in the subsequent declaration, they do not have the same meaning as in struct S { ... }; SS, T; struct S { ... }; SS, T; // declare two instances struct S which is not equivalent to struct S {...}; SS ST; // error`

+13
source

Source: https://habr.com/ru/post/1437832/


All Articles