结构体的内存布局和偏移量的关系
#include "stdio.h"
#include <stdlib.h>
#include "string.h"
//一旦结构体定义,内存布局一定
typedef struct AdvTea{
char name[64];
int age;
int p;
char *aliname;
}AdvTea;
void main()
{
AdvTea t1;
AdvTea *P1 = NULL;
P1-1;//在CPU中计算
P1-P1;
P1 = &t1;
//P1+P1;错误,指针相加无意义
{
int offset1 = 0,offset2 = 0;
offset1 = (int)&(P1->aliname) - (int)P1;
offset2 = (int)&(((AdvTea*)0)->aliname);
printf("%d,%d\n",offset1,offset2);
}
system("pause");
}