定义一个宏获取结构体中变量相对结构体开始的偏移量
#include <iostream>using namespace std;struct test{int a;char b;int c;char d;};#define find(type, var) (unsigned int)(&(((type *)(0))->var))int main(){int a = find(test, a);//0int b = find(test, b);//4int c = find(test, c);//8int d = find(test, d);//12cout << a << endl << b << endl << c << endl << d << endl;cout << sizeof(test) << endl;//16system("pause");return 0;}