according to the C Standard (and K&R) the syntax of the Comma-Operator is as follows:
expression:
assignment-expression
expression, assignment-expression
But why does this statement work?
5+5, 1+1;
5+5 and 1+1 are not assignment-expressions, but the C Standard requires assignment-expressions as operands for the Comma-Operator.
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
which finally are ⊃ additive-expression + multiplicative-expression
.
So no, 5+5 is indeed ∈ assignment-expression
.
⊃ is the "contains" relation.
The way the C grammar is defined may not be obvious in the first place.
First, let's look how the assignment-expression
is defined:
(6.5.16) assignment-expression:
conditional-expression
unary-expression assignment-operator assignment-expression
This means that it can be either conditional-expression
or the latter combination of tokens. The former is defined as:
(6.5.15) conditional-expression:
logical-OR-expression
logical-OR-expression ? expression : conditional-expression
Eventually, you will encounter:
(6.5.7) shift-expression:
additive-expression
shift-expression << additive-expression
shift-expression >> additive-expression
where additive-expression
corresponds to expressions such 1+1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With