container_of宏分析
来源:互联网 发布:js复杂数据类型 编辑:程序博客网 时间:2024/05/21 09:33
container_of宏分析
#define container_of(ptr, type, member)({ /
const typeof( ((type *)0)->member ) *__mptr = (ptr); /
(type *)( (char *)__mptr - offsetof(type,member) );})
Ø 计算member在type中的偏移量
#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
A-------------> TYPE *ptype,*pmember;
B-------------> ptype = (TYPE*)0;
C-------------> pmember =ptype->MEMBER;
D-------------> MEMBER的地址为:&pmember;
E------------->强制转换为size_t;
由于B中TYPE指针的初始地址为0,则pmember实际为MEMBER成员在TYPE结构中的偏移量。
Ø 计算一个具体结构体中member成员的实际地址
const typeof( ((type *)0)->member )*__mptr = (ptr);
A-------------> typeof( ((type*)0)->member )获得member成员的类型;
B-------------> 定义一个member成员的类型,并初始化为ptr;
Ø 计算type的地址
(type *)( (char *)__mptr -offsetof(type,member) );})
A------------->用实际的地址减去偏移量及为type结构体的地址。
- container_of宏使用分析
- container_of宏分析
- container_of宏定义分析
- container_of宏分析
- container_of 宏、offsetof 宏 分析
- container_of 宏的具体分析
- Linux内核:container_of宏分析
- container_of分析
- container_of 分析
- container_of分析
- container_of分析
- container_of分析
- container_of分析
- container_of分析
- container_of分析
- container_of分析
- container_of分析
- container_of分析
- C# Unicode和ascii转换
- C# TextBox中的 Validating 与 Validated 事件
- Java中堆和栈的区别
- 25个实用的Photoshop菜单和导航教程
- Win+R中的快捷命令
- container_of宏分析
- Block的使用 iphone
- Activity启动方式
- Git In Five Minutes (zz)
- CSS下解决IE6PNG半透明的问题(亲测 无错)
- Windows XP下 安装和配置Apache2.2.22服务器+PHP5+Mysql5
- 20个视频播放器界面欣赏及点评
- Android socket
- Ubuntu Linux 下 Ffmpeg 及 Mencoder 安装使用小结