container_of(ptr, type, member)

来源:互联网 发布:巨人网络福利待遇 编辑:程序博客网 时间:2024/05/10 05:42

446 #define container_of(ptr, type, member) ({                      /

447        const typeof( ((type *)0)->member ) *__mptr = (ptr);    /

448      (type *)( (char *)__mptr - offsetof(type,member) );})

                   成员变量对应的变量的地址 -  偏移     


member:成员变量

ptr   :成员变量对应的变量的地址.  

container_of()思想:结构体成员变量对应的变量的地址  减去 在成员在结构体中的偏移  =  结构体首的首地址


参考博客

http://blog.csdn.net/goldfighter/article/details/7682313


                  


0 0
原创粉丝点击