Search code examples
ccomma-operator

C Standard - Comma Operator Syntax


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.


Solution

  • assignment-expressionconditional-expressionlogical-OR-expressionlogical-AND-expressioninclusive-OR-expressionexclusive-OR-expressionAND-expressionequality-expressionrelational-expressionshift-expressionadditive-expression which finally are ⊃ additive-expression + multiplicative-expression.

    So no, 5+5 is indeed ∈ assignment-expression.


    ⊃ is the "contains" relation.