
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源
去关联
#define container_of(ptr, type, member) ({
const typeof( ((type *)0)->member ) *__mptr = (ptr);
(type *)( (char *)__mptr - offsetof(type,member) );})
ptr:指向结构字段的指针。
type:包装指针的结构类型(即指针的类别)
member:ptr指向的结构内字段的名称(如结构体中的成员)
举个例子:
struct person{
int age;
char *name;
}somebody;
struct person *the_person
the_person = container_of (somebody.name, struct person, name);
最终结果the_person由container_of考虑到name从该结构开始处的偏移量,进而获取正确的指针位置。