摘要: Linux内核中的container_of#define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );})其中typeof(x)是gcc对c的一种扩展,指的是x的类型。首先:(type*)0假设将0地址强制转换成传入的type类型,对type类型取其member成员,通过typeof运算符,临时生成类型为typeof(x)__mptr的指针,且赋值为 阅读全文
posted @ 2013-04-30 09:30 Richard Zhong 阅读(266) 评论(0) 推荐(0) 编辑