#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); //0 int b = find(test, b); //4 int c = find(test, c); //8 int d = find(test, d); //12 cout << a << endl << b << endl << c << endl << d << endl; cout << sizeof(test) << endl; //16 system("pause"); return 0; }
定义一个宏获取结构体中变量相对结构体开始的偏移量
最新推荐文章于 2019-11-19 22:36:12 发布