目的:获取一个结构体成员相对于该结构首地址的偏移量
C代码如下:
#include <stdio.h>
#define GET_OFFSET(data,member) (size_t)(&(((typeof(data)*)0)->member))
typedef struct student{
int a;
char ch[2];
double d;
}student_t;
int main(int argc, char const *argv[])
{
student_t stu ;
int offset ;
offset= GET_OFFSET