在struct的前後加上 ...
#pragma pack(push) /* push current alignment to stack */
#pragma pack(1) /* set alignment to 1 byte boundary */
typedef struct _test
{
char ch0; //byte 1
char ch1; //byte 1
int in; //byte 4
short sh; //byte 2
}test;
#pragma pack(pop) /* restore original alignment from stack */
參考資料:
1. http://changeway.pixnet.net/blog/post/7669656-data-structure-alignment
2. http://en.wikipedia.org/wiki/Data_structure_alignment
沒有留言:
張貼留言