Statement Expressions

C++ 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. This construct, an orthogonal extension of GNU C, is currently supported only in IBM C++.

         .--------------.
         V              |
>>-(--{----statement--;-+--}--)--------------------------------><
 
 

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 feature 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;} )

Related References

IBM Copyright 2003