I\'ve noticed that sometimes, C macros are written as something like this:
#define foo(bar) ({ ++bar; })
After some experimentation, I\'ve
The cool thing about statement expressions (if there is a cool thing) is that the last statement is the result of the expression.
#define foo(bar) ({ ++bar; 3.1415927; })
int i = 0;
float pi = foo(i);
This is a GNU extension called statement expressions.
When declaring macros in standard-C, you often see do...while(0)
loops used for similar purposes (ie creating a block scope). A statement expression is superior to the loop hack because it can return a value. If you want to do something similar in standard-C, you'd have to define an additional function and lose the convenience of lexical scoping.
() is an expression. ({code; code;}) is a compound statement inside an expression. That is a GNU C extension.
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html
EDIT: wow, I got that link from Google and didn't notice it was for gcc 2.95 at first. Ancient!