当我检查container_of
Linux Kernel 中宏的定义时,我看到一个复合语句作为宏定义,
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
但是,在我看来,不清楚的问题是哪个语句被视为右值。显然最后一条语句的结果被用作右值,但为什么呢?
(type *)( (char *)__mptr - offsetof(type,member) );
例如,下面的代码示例在 C 中是否合法?
int g_count = 0xFF;
#define GLOBAL_COUNT do {g_count;} while(0)
int main(int argc, char *argv[])
{
int local;
local = GLOBAL_COUNT;
local = 0;
GLOBAL_COUNT = local;
return 0;
}
复合语句中变量的赋值规则是什么?