?
本文檔使用 php中文網(wǎng)手冊(cè) 發(fā)布
在頭文件<stddef.h>中定義 | ||
---|---|---|
#define offsetof(type,member)/ *實(shí)現(xiàn)定義的* / |
宏的offsetof擴(kuò)展為size_t類(lèi)型的常量,其值是從指定類(lèi)型的對(duì)象開(kāi)始到指定成員(包括填充(如果有))的偏移量(以字節(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運(yùn)算符返回的無(wú)符號(hào)整數(shù)類(lèi)型(typedef) |
---|