#include <iostream>
#include <stdio.h>
using namespace std;
#define OFFSET(struc, m) (size_t)(&(((struc*)0)->m))
struct MyStruct
{
MyStruct()
{
a = 0;
b = 'a';
c = 0.0f;
}
int a;
float c;
char b;
};
void main()
{
cout << OFFSET(MyStruct, a) << endl;
}
(s *)0 是骗编译器说有一个指向类(或结构)s的指针,其值0
&((s *)0)->m 是要取得类s中成员变量m的地址
由于这个类的基址为0,这时m的地址当然就是m在s中的偏移了