分类: C/C++
2011-08-25 21:05:12
sunjiangang-ok2011-08-26 11:32:39
sygspjlsj2011-08-26 11:12:18
指针ptr指向结构体type中的成员member;通过指针ptr,返回结构体type的起始地址
#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)
1.ptr为物理地址,其类型和member类型一致,最终使用typeof( ((type *)0)->member )