HP C/iX Reference Manual (31506-90011)

Chapter 5 87
Expressions
Comma Operator
Comma Operator
The comma operator is a binary operator whose operands are expressions. The expression
operands are evaluated from left to right.
Syntax
expression
::=
assignment-expression
expression
,
assignment-expression
Description
The comma operator is a "no-operation" operator. Its left operand is evaluated for its side
effects only. Its value is discarded. The right operand is then evaluated and the result of
the expression is the value of the right operand.
Because the comma is a punctuator in lists of function arguments, you need to use care
within argument lists to ensure that the comma is treated as a comma operator and not as
an argument separator.
f(a, (b=7, b), c);
This example passes three arguments to f(). The first is the value of a, the second is the
value of b which is set equal to 7 before the function call, and the third is the value of c.
The comma separating the assignment expression and the argument b is enclosed in
parentheses. It is therefore interpreted as a comma operator and not as an argument
separator.
Examples
func(a, (b=0, b), c) /* set b to 0 before passing it to func. */
index++, a = index /* increment index and then assign it to a.*/
i=0, j=0, k=0 /* initialize i,j,k to 0 */