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

 

  #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

 

注意((type *)0)的使用。比如:((void *)0)();

((TYPE *)0)->MEMBER;--->这是指MEMBER在结构体TYPE中的偏移。

相关文章: