a vesszőoperátornak [...] az, hogy
Érdemes idézni a szabványból:
The left operand of a comma operator is evaluated as a void expression; there is a sequence point after its evaluation. Then the right operand is evaluated; the result has its type and value. [...]
Valamint
a függvényhívásnál a paramétereket elválasztó vessző nem vesszőoperátor
itt is (mivel ez példaként szerepel, ezért nem normatív, hanem informatív):
As indicated by the syntax, the comma operator (as described in this subclause) cannot appear in contexts where a comma is used to separate items in a list (such as arguments to functions or lists of initializers). On the other hand, it can be used within a parenthesized expression or within the second expression of a conditional operator in such contexts.
Ebben az a szép, hogy a szintaxis (a nyelv formális nyelvtana) diktálja, hogy a "," karakter mikor mi. A fenti paragrafus olyan függvényhívást mutat példának, hogy
f(a, (t=3, t+2), c)
azzal a kommentárral, hogy
the function has three arguments, the second of which has the value 5.
De ami igazán szép szerintem, az a második megjegyzés: within the second expression of a conditional operator. (Kiemelés tőlem.) Saját példáim:
int a[] = { 1 , 2 ? 3 : 4 };
int b[] = { 1 ? 2 , 3 : 4 };
int c[] = { 1 ? 2 : 3 , 4 };
Az "a"-nak az elemei: { 1, 3 }.
A "b"-nek az elemei: { 3 }.
A "c"-nek az elemei: { 2, 4 }.
A "b"-nél a nyelvtan alapján a vessző nem tudja "félbevágni" a feltételes operátor második operandusát, az "a"-ban lévő vesszőnél viszont a feltételes operátort még el sem kezdtük, a "c-"ben lévő vesszőnél pedig már befejeztük.
A "b"-nek a szintaxisfája:
conditional-expression
|
----------------------------------------------------+----------------------------------------
logical-OR-expression ? expression : conditional-expression
| | |
logical-AND-expression --------------------------+--------------- logical-OR-expression
| expression , assignment-expression |
inclusive-OR-expression | | ...
| assignment-expression ... |
exclusive-OR-expression | | 4
| conditional-expression 3
AND-expression |
| logical-OR-expression
equality-expression |
| ...
relational-expression |
| 2
shift-expression
|
additive-expression
|
multiplicative-expression
|
cast-expression
|
unary-expression
|
postfix-expression
|
primary-expression
|
constant
|
integer-constant
|
----------------+-------------------
decimal-constant integer-suffix(opt)
| |
nonzero-digit []
|
1