Comma statement in C ++ 11 (sequence)

The standard mentions f (a, (t = 3, t + 2), c); , which will be an assignment expression, followed by an expression for the second operator, as I understand it.

But in grammar, it maps to:

expression:

Assignment expression

expression, assignment expression

Working draft, standard for programming C ++ language Revision N4140 (November 2014)

Is anyone so good as to explain to me, please, what is it that I am absent here?

+4
source share
4 answers

When you see

 expression:
    assignment-expression
    expression, assignment-expression

, . , assignment-expression, - . expression, assignment-expression

, , , - .

, , (t = 3, t + 2), 2 - - " , " " ".

, - t + 2,

assignment-expression
-> conditional-expression
--> logical-or-expression
---> logical-and-expression
----> inclusive-or-expression
-----> exclusive-or-expression
------> and-expression
-------> equality-expression
--------> relational-expression
---------> shift-expression
----------> additive-expression - this is what you see
+8

(. . 1.6 N4140).

, .

, [expr.ass] (ยง5.18) :

assignment-expression:
   conditional-expression
   logical-or-expression assignment-operator initializer-clause
   throw-expression

assignment-operator: one of
   = *= /= %= += -= >>= <<= &= ^= |=

, assignment-expression conditional-expression throw-expression, .

, a = b, throw 10 cond ? c : d .

+2

,

:

& ;

& ; , -

, - , t=3, t+2 .

? , , , . ( , "( )" , , , , .)

, , , * , +:

-:

& ; -

& ; * pm-expression

& ; / pm-expression

& ; % pm-expression

-:

& ;

& ; additive-expression +

& ; additive-expression -

2 + 3 * 4 2, 3 4 pm-, , , . , , 2 + 3 , , 2 + 3 * 4 . 3 * 4 , 2 + 3 * 4 . , 3 * 4 +.

2 * 3 + 4, 3 + 4 , pm-, . , 2 * 3 , , 2 * 3 + 4 2 * 3 +.

, , .

, "a, b, c", , b, c , -, b, c . a, b , , a, b, c a, b .

, : " a, ( b), c)" , " ( a, b), c".

operator,. :

struct X {};
X operator,(X, X);
X a, b, c;
X d = (a, b, c);

,

X d = operator,(operator,(a,b), c);

X d = operator,(a, operator,(b,c));

( operator,, .)

+1
 f(a,(t=3,t+2),c);

Here it is first stored 3in a variable t, then it calls a function f()with three arguments. This means that the value of the second argument becomes 5and goes to the function.

0
source

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


All Articles