alignment
struct{
char data1;
short data2;
int data3;
char data4;
}
==>
struct{
char data1;
char padding1[1]; // short需要align到2byte
short data2;//不需要padding, int已经align到4byte
int data3;
char data4;
char padding2[3];//虽然已经是最后一个元素 但是为了避免用在数组里的问题时 也不得不加上padding
}
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.