#include<iostream>
typedef struct _tTask
{
int a;
int b;
double c;
int *node;
}tTask;
using namespace std;
int main(void)
{
int c = 1;
tTask task1;
task1.a = 1;
task1.b = 2;
task1.c = 1.5;
int *node = &c;
unsigned int d = (unsigned int)&(((tTask *)0)->a);
cout << d << endl;
return 0;
}
以上,找到了结构体中成员的偏移量为d,后序如果需要根据某成员的地址转换为结构体只需要执行
(tTask *)((unsigned int)node - d);
即可得到。