#include<stddef.h>
size_t offsetof ( type, member )
#define offsetof ( TYPE, MEMBER) \
( ( size_t ) & ( ( TYPE *) 0 ) ->MEMBER )
The macro return the offset of the field “member” from the start of struct “type”.
例如,
typedef struct {
int a;
int b;
int c;
int d;
} PAD_t;
offsetof (PAD_t, d) 返回12.
根据需要,(TYPE *)0 可以改为非0地址,例如(TYPE *)100,此时 offsetof (PAD_t, d) 返回112.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/172101.html原文链接:https://javaforall.cn