offsetoff-用来计算结构体存储时元素存储地址相对于起始存储地址的一个偏移量的一个宏
实现代码:
#include<stdio.h>
#define Offsetof(struct_name,member_name) (int)&(((struct_name*)0)->member_name)
struct S
{
int a;
char b;
double c;
};
int main()
{
struct S s = { 0 };
printf("%d\n", Offsetof(struct S, a));
printf("%d\n", Offsetof(struct S, b));
printf("%d\n", Offsetof(struct S, c));return 0;
}