Linux源码学习——offsetof与container_of宏 发表于 2019-07-18 | 更新于: 2019-07-18 | 分类于 Linux , Linux源码学习 | 阅读次数: 字数统计: 55 | 阅读时长 ≈ 1 Linux内核源码果真精髓,相见恨晚。 offsetof 宏定义如下 1#define offsetof(type, member) (size_t)&(((type*)0)->member) container_of 宏定义如下 123#define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) ❤采之欲遗谁,所思在远道。❤