IBM extension

Statement expressions

A compound statement is a sequence of statements enclosed by braces. In GNU C, a compound statement inside parentheses may appear as an expression in what is called a statement expression.

Read syntax diagramSkip visual syntax diagramStatement expression syntax
         V              |

The value of a statement expression is the value of the last simple expression to appear in the entire construct. If the last statement is not an expression, then the construct is of type void and has no value.

The statement expression can be combined with the typeof operator to create complex function-like macros in which each operand is evaluated only once. For example:

#define SWAP(a,b) ( {__typeof__(a) temp; temp=a; a=b; b=temp;} )
End of IBM extension