struct type1 { //... int member1; //... }; struct type1 obj1;
而ptr1是obj1中成员member1的地址,如何定义宏#define start_add(ptr1,type1,member1)来获取obj1起始地址?
offsetof
#define start_add(ptr1,member1) ((type1 *)((char *)(ptr1) - offsetof(type1,member1)))