More information on `({});` in C?

后端 未结 3 1186
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 00:58

I\'ve noticed that sometimes, C macros are written as something like this:

#define foo(bar) ({ ++bar; })

After some experimentation, I\'ve

3条回答
  •  深忆病人
    2021-01-18 01:44

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

提交回复
热议问题