2012年10月22日

定义一个宏获取结构体中变量相对结构体开始的偏移量

摘要: #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 阅读全文

posted @ 2012-10-22 14:26 linzuxin 阅读(210) 评论(0) 推荐(0) 编辑

导航