©
This document usesPHP Chinese website manualRelease
在头文件 |
|
|
---|---|---|
#define offsetof(type,member)/ *实现定义的* / |
|
|
宏的offsetof扩展为size_t类型的常量,其值是从指定类型的对象开始到指定成员(包括填充(如果有))的偏移量(以字节为单位)。
#include#include struct S { char c; double d;}; int main(void){ printf("the first element is at offset %zu\n", offsetof(struct S, c)); printf("the double is at offset %zu\n", offsetof(struct S, d));}
可能的输出:
the first element is at offset 0the double is at offset 8
size_t |
由sizeof运算符返回的无符号整数类型(typedef) |
---|