struct {char a[3];short int b;long int c;char d[3];};
现在,你可能会认为应该可以打包这个结构到内存中,如下所示:
+-------+-------+-------+-------+| a | b |+-------+-------+-------+-------+| b | c |+-------+-------+-------+-------+| c | d |+-------+-------+-------+-------+
但是如果编译器排列,它在处理器上要容易得多是这样的:
+-------+-------+-------+| a |+-------+-------+-------+| b |+-------+-------+-------+-------+| c |+-------+-------+-------+-------+| d |+-------+-------+-------+
+-------+-------+-------+-------+| a | pad1 |+-------+-------+-------+-------+| b | pad2 |+-------+-------+-------+-------+| c |+-------+-------+-------+-------+| d | pad3 |+-------+-------+-------+-------+