求 linux/list.h 部分解读list_entry()
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); \
pos = pos->next)
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))听说这一句子要给出type与member就能找到对应的节点,求具体解释
[解决办法]
(unsigned long)(&((type *)0)->member))
得到0地址处变量type对应member的地址,就是member对应type的偏移值
然后ptr值减去member偏移值就得到 对应type变量的首地址了。