首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

C的offsetof跟container_of

2013-07-09 
C的offsetof和container_of#include stdio.h#include stddef.h// #define offsetof(s, m) ? (size_t)&

C的offsetof和container_of

#include <stdio.h>

#include <stddef.h>

// #define offsetof(s, m) ? (size_t)&(((s *)0)->m)

?

struct A

{

? ? ? ? int a;

? ? ? ? int b;

};

?

int main()

{

? ? ? ? printf("%d\n", offsetof(struct A, b));

? ? ? ? return 0;

}

http://blog.csdn.net/pengzhixi/article/details/4275887

?

#define container_of(ptr, type, member) \

? ((type *) ((char *) (ptr) - offsetof(type, member)))

?

热点排行