@LIUHUAN
2019-03-11T14:32:20.000000Z
字数 766
阅读 960
linux
struct list_head {struct list_head *next, *prev;};
typedef struct Data{int n;// other datastruct list_head list;}Data;Data d;struct list_head l = list_entry(&d,Data,list);
#define list_entry(ptr, type, member) \container_of(ptr, type, member)#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)
--------------------- // 地址空间| <-offset -> |地址0 member地址