gcc: Conditionals
1
1 6.7 Conditionals with Omitted Operands
1 ======================================
1
1 The middle operand in a conditional expression may be omitted. Then if
1 the first operand is nonzero, its value is the value of the conditional
1 expression.
1
1 Therefore, the expression
1
1 x ? : y
1
1 has the value of 'x' if that is nonzero; otherwise, the value of 'y'.
1
1 This example is perfectly equivalent to
1
1 x ? x : y
1
1 In this simple case, the ability to omit the middle operand is not
1 especially useful. When it becomes useful is when the first operand
1 does, or may (if it is a macro argument), contain a side effect. Then
1 repeating the operand in the middle would perform the side effect twice.
1 Omitting the middle operand uses the value already computed without the
1 undesirable effects of recomputing it.
1