为什么我们需要在块宏周围加括号?

6
在Linux中,container_of宏被包含在看似“额外”的括号中:
 #define container_of(ptr, type, member) ({ \
                const typeof( ((type *)0)->member ) *__mptr = (ptr); 
                (type *)( (char *)__mptr - offsetof(type,member) );})

我们可以不使用它,而改用

 #define container_of(ptr, type, member) { \
                const typeof( ((type *)0)->member ) *__mptr = (ptr); 
                (type *)( (char *)__mptr - offsetof(type,member) );}

这些括号是必需的还是只是为了预防?


这应该标记为GCC而不是C...... - David Heffernan
2个回答

11

9

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接