标签:mil style 就是 span warning isa class variant 一个
用于获取一个对象的类型,比如:
unsigned int a = 1; // typeof (a) is unsigned int short b = 2; // typeof (b) is short
#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
获取某个成员变量(MEMBER)在其所在的结构体(TYPE)里的偏移:
因为该对象的起始地址为0,那么MEMBER处的地址自然是其在此结构体中的偏移地址。
// non ISO variant from linux kernel; checks ptr type, but triggers ‘ISO C forbids braced-groups within expressions [-Wpedantic]‘ // __extension__ is here to disable this warning #define container_of(ptr, type, member) ( __extension__ ({ const typeof( ((type *)0)->member ) *__mptr = (ptr); (type *)( (char *)__mptr - offsetof(type,member) );}))
它的作用是根据一个结构体成员的地址来获取该结构体的地址:
标签:mil style 就是 span warning isa class variant 一个
原文地址:https://www.cnblogs.com/qiyuexin/p/12619507.html