b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

offsetof_firetaker的专栏

电脑杂谈  发布时间:2016-05-30 02:00:21  来源:网络整理

你是否正在寻找关于offsetof的内容?让我把最吸引人的东西奉献给你:

offsetof
Retrieves the offset of a member from the beginning of its parent structure.

size_t offsetof(structName, memberName);

Parameters:
structName : Name of the parent data structure.
memberName :Name of the member in the parent data structure for which to determine the offset.

Return Value : offsetof returns the offset in bytes of the specified member from
the beginning of its parent data structure. It is undefined for bit fields.
Remarks :
The offsetof macro returns the offset in bytes of memberName from the beginning of the structure specified by structName. You can specify types with the struct keyword.

Note :
offsetof is not a function and cannot be described using a C prototype.

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

s是一个结构名,它有一个名为m的成员(s和m 是宏offsetof的形参,它实际是返回结构s的成员m的偏移地址.

(s *)0 是骗编译器说有一个指向类(或结构)s的指针,其地址0

&((s *)0)->m 是要取得类s中成员变量m的地址. 因基址为0,这时m的地址当然就是m在s中的偏移

最后转换size_t 型,即unsigned int,。

以上就是关于offsetof的全部内容,相信你一定会非常满意。


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shenmilingyu/article-6828-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...