【发布时间】:2012-11-23 06:57:40
【问题描述】:
Linux内核中的container_of()宏定义为:
#define container_of(ptr, type, member) ({ \
const typeof( ((type*)0)->member) * __mptr =(ptr);\
(type*)( (char*)__mptr - offsetof(type,member) );})
为什么这里使用((type*)0)->member,而不是(type*)->member?
【问题讨论】:
-
看起来有人试图将 null 转换为 type*,然后访问它的成员成员。
-
@Nocturno 不只是尝试。 :)