本文共 427 字,大约阅读时间需要 1 分钟。
#include/* *取(结构体)成员偏移量 * */#define offset(TYPE,MEMBER) ((int)&((TYPE *)0)->MEMBER) #pragma pack(1)//设置对其方式为1个字节struct test{ char c; int n; int m; char *ptr;};#pragmaint main(){ int pos = offset(struct test,c); printf("pos(c) = %d\n",pos); pos = offset(struct test,n); printf("pos(n) = %d\n",pos); pos = offset(struct test,m); printf("pos(m) = %d\n",pos); pos = offset(struct test,ptr); printf("pos(ptr) = %d\n",pos);}
转载地址:http://pxuhj.baihongyu.com/