这个宏的含义

C语言 码拜 9年前 (2015-05-11) 896次浏览 0个评论
 
#define  offsetof(TYPE, MEMBER)  ((size_t) & ((TYPE*)0)->MEMBER)

这个宏的作用和功能是什么,

4分
获取结构TYPE的成员变量MEMBER在结构中的偏移量,编译时就能计算出
4分
结构成员在结构中的偏移
4分
这个不一定地结构, 也可以是类
c、c++ 可以无耻的把0转换成 类/结构 指针, 再计算出成员变量的偏移量。
&得到的结果就是偏移量。
4分
结构体或类成员的偏移量
4分
         offsetof( type,  member-designator)

which expands to an integral constant expression that has type size_t, 
the value of which is the offset in bytes, to the structure member
(designated by member-designator ), from the beginning of its
structure (designated by type ).


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明这个宏的含义
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!