我總是假設,因爲他們在這裏http://en.wikipedia.org/wiki/Data_structure_alignment說,「重要的是要注意的是,最後一個成員則以用,使結構的總規模應該是一個多所需的字節數是很重要的任何結構成員」填充
的最大對齊因此,對於這樣的結構,其規模應該在32處理器
typedef struct
{
double s; /* 8 bytes */
char c; /* 7 bytes padding at the end of make the total size 8*2 */
} structa_t;
所以我很驚訝的大小是16是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)
必須的意思是,你已經字節說的位 – jman
也許簡單地'雙'只需要對齊在一個四字節的邊界? – sth
您錯過了關閉'* /'的評論。 –