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

offsetof宏用于获取结构体中某个成员相对于结构体起始位置的偏移量。该宏的参数为结构体名和成员名,返回值是成员的偏移量(以字节为单位)。文章通过示例解释了offsetof的使用,并展示了如何利用offsetof来计算结构体的头部地址。
最低0.47元/天 解锁文章
999

被折叠的 条评论
为什么被折叠?



