打印结构体偏移

2016-12-07 20:34:50来源:CSDN作者:kelsel人点击

第七城市
#include <stdio.h>#define OFFSET(x, y)   &((x *)0)->ystruct TestStruct {    int mVar1;    int mVar2;    int mVar3;};void OffsetTestStruct(){    fprintf(stderr, "sizeof(struct TestStruct) %d/n", sizeof(struct TestStruct));    fprintf(stderr, "-- mVar1 offset : %d/n", OFFSET(TestStruct, mVar1));    fprintf(stderr, "-- mVar2 offset : %d/n", OFFSET(TestStruct, mVar2));    fprintf(stderr, "-- mVar3 offset : %d/n", OFFSET(TestStruct, mVar3));}struct TestStruct2 {    int mVar1;    long long mVar2;    int mVar3;};void OffsetTestStruct2(){    fprintf(stderr, "sizeof(struct TestStruct2) %d/n", sizeof(struct TestStruct2));    fprintf(stderr, "-- mVar1 offset : %d/n", OFFSET(TestStruct2, mVar1));    fprintf(stderr, "-- mVar2 offset : %d/n", OFFSET(TestStruct2, mVar2));    fprintf(stderr, "-- mVar3 offset : %d/n", OFFSET(TestStruct2, mVar3));}
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台