機能 |
構造体メンバのオフセット位置(バイト単位)を取得する。 size_t型をもつ整数定数式に展開する。 |
||||
---|---|---|---|---|---|
定義 |
#include <stddef.h> size_t offsetof ( 型, メンバ指示子 ) |
||||
引数 |
|
||||
戻り値 |
指定した型(構造体)の先頭からメンバ指示子(構造体メンバ)までのバイト単位でのオフセット値を返す。 |
||||
実装例 |
#include <stddef.h> #include <stdio.h> int main(void) { struct ABC { int a; char b; double c; }; size_t s1, s2, s3; s1 = offsetof(struct ABC, a); s2 = offsetof(struct ABC, b); s3 = offsetof(struct ABC, c); printf("a: %d\n", s1); printf("b: %d\n", s2); printf("c: %d\n", s3); return 0; } |
||||
実行結果 |
a: 0 b: 4 c: 8 |
offsetof