我总是假设,正如他们在这里所说的http://en.wikipedia.org/wiki/Data_structure_alignment,“重要的是要注意最后一个成员填充了所需的字节数,因此结构的总大小应该是任何结构成员的最大对齐的倍数"
所以对于这样的结构,它的大小在 32 处理器上应该是 16
typedef struct
{
double s; /* 8 bytes */
char c; /* 7 bytes padding at the end of make the total size 8*2 */
} structa_t;
所以我对尺寸是 12 而不是 16 感到非常惊讶!这是为什么 ?有人可以对此有所了解吗?
sizeof(double) = 8
sizeof(structa_t) = 12
顺便说一句,所以系统信息
$ uname -a
Linux 2.6.18-8.el5xen #1 SMP Thu Mar 15 21:02:53 EDT 2007 i686 i686 i386 GNU/Linux
$ gcc --version
gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-52)