#include<stdio.h>
typedef struct
{
short unsigned dataIcon;
short unsigned dataNum;
char empty[14];
long dataDate;
}DAILYITEM;
main()
{ printf("%d=%d+%d+%d+%d\n",sizeof(DAILYITEM),
sizeof(short unsigned),
sizeof(short unsigned),
sizeof(char)*14,
sizeof(long));
return 0;
}
编译器 VC6 输出:
24=2+2+14+4
Press any key to continue
----------------解决方案--------------------------------------------------------
扔掉!我的是22
----------------解决方案--------------------------------------------------------
字节对齐问题
#include<stdio.h>
#pragma pack(1) //强制1字李对齐
typedef struct
{
short unsigned dataIcon;
short unsigned dataNum;
char empty[14];
long dataDate;
}DAILYITEM;
#pragma pack( ) //恢复
main()
{ printf("%d=%d+%d+%d+%d\n",sizeof(DAILYITEM),
sizeof(short unsigned),
sizeof(short unsigned),
sizeof(char)*14,
sizeof(long));
return 0;
}
----------------解决方案--------------------------------------------------------