?
This document uses PHP Chinese website manual Release
在頭文件<stddef.h>中定義 | ||
---|---|---|
#define offsetof(type,member)/ *實現(xiàn)定義的* / |
宏的offsetof擴展為size_t類型的常量,其值是從指定類型的對象開始到指定成員(包括填充(如果有))的偏移量(以字節(jié)為單位)。
#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運算符返回的無符號整數(shù)類型(typedef) |
---|