图片附件: 游客没有浏览图片的权限,请
登录 或
注册
#include<stdio.h>
#include <stddef.h>
#define PN_OFFSET_SIZEOF(st,sm) printf("%s\t%d\t%d\n", #st"."#sm, offsetof(st, sm), sizeof(((st *)0)->sm))
typedef struct person
{
char name[32];
char data[1024];
struct person * next;
} PERSON;
typedef struct abcdef
{
char a1;
int a2;
short a3;
} ABCDEF;
int main()
{
printf("结构成员\t偏移量\t大小\n");
PN_OFFSET_SIZEOF(PERSON, name);
PN_OFFSET_SIZEOF(PERSON, data);
PN_OFFSET_SIZEOF(PERSON, next);
printf("结构大小\t\t%d\n\n", sizeof(PERSON));
PN_OFFSET_SIZEOF(ABCDEF, a1);
PN_OFFSET_SIZEOF(ABCDEF, a2);
PN_OFFSET_SIZEOF(ABCDEF, a3);
printf("结构大小\t\t%d\n\n", sizeof(ABCDEF));
return 0;
}