Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the comma in a variable list a sequence point?

Tags:

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?

like image 796
edA-qa mort-ora-y Avatar asked Jun 20 '11 15:06

edA-qa mort-ora-y


People also ask

Is comma a sequence point?

Although the comma operator is a sequence point, the commas that separate the arguments in a function call are not comma operators; they're just punctuation. Once again, the order of evaluation of the function arguments is unspecified.

What does comma mean in binary?

The comma operator (represented by the token, ) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type).

What does comma after variable in Python?

By adding the comma to the assignment target list, you ask Python to unpack the return value and assign it to each variable named to the left in turn. Most often, you see this being applied for functions with more than one return value: base, ext = os.path.splitext(filename)

What are commas used for in coding?

The comma operator ( , ) evaluates each of its operands (from left to right) and returns the value of the last operand. This lets you create a compound expression in which multiple expressions are evaluated, with the compound expression's final value being the value of the rightmost of its member expressions.


1 Answers

I believe behavior is well-defined because of 8[dcl.decl]/3

Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself.

Which is even additionally explained in a footnote as

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; 
like image 124
Cubbi Avatar answered Sep 20 '22 15:09

Cubbi