小编Kui*_*ang的帖子

C块变为表达式:({int a = 1; int b = 2; a + b;})等于3

在阅读http://en.wikipedia.org/wiki/C_preprocessor#Multiple_evaluation_of_side_effects时,我遇到了这个例子:

\#define max(a,b) \
   ({ typeof (a) _a = (a); \
       typeof (b) _b = (b); \
     _a > _b ? _a : _b; }) // WHY DOES THIS LINE WORK?
Run Code Online (Sandbox Code Playgroud)

你可以像函数一样使用它,即max(1,2)是一个评估为2的表达式.

我的问题是,构造如何({ statment-list last-expression; })评估last-expression的值?具体来说,这个结构的解析树是什么样的?我认为{ }总是意味着复合语句,而且语句没有值.我试着在C语法中挖掘,仍然无法解决这个问题.

c macros gcc c-preprocessor

5
推荐指数
1
解决办法
1342
查看次数

标签 统计

c ×1

c-preprocessor ×1

gcc ×1

macros ×1