#include <stdio.h>
/*
*取(结构体)成员偏移量
* */
#define offset(TYPE,MEMBER) ((int)&((TYPE *)0)->MEMBER)
#pragma pack(1)//设置对其方式为1个字节
struct test
{
char c;
int n;
int m;
char *ptr;
};
#pragma
int 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);
}
取(结构体)成员偏移量
最新推荐文章于 2018-06-17 21:39:49 发布