本文收集Linux内核中各种稀奇古怪的宏定义。
#define get_addr(type, member, mem_addr) (type*)(mem_addr - &(((type*)0)->member))
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#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) );})
阅读(801) | 评论(0) | 转发(0) |