©
This document uses PHP Chinese website manual Release
在头文件<stddef.h>中定义 | ||
---|---|---|
#define offsetof(type,member)/ *实现定义的* / |
宏的offsetof扩展为size_t类型的常量,其值是从指定类型的对象开始到指定成员(包括填充(如果有))的偏移量(以字节为单位)。
#include <stdio.h>#include <stddef.h> 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) |
---|