Alignment: Each member variable in the struct is stored as a multiple of the length of the memory space that the type occupies. More than 4 bytes by 4 bytes
Alignment is also: the number of bits of the previous type in the struct is determined by the type of variable that follows it!
Completion: In the structure of the storage space at the end of the structure of the largest member of the space occupied by the length of the space to fill in multiples. The count is 4 bytes greater than 4 bytes.
Completion: The last length of a struct is determined by the data type of the largest member variable in the struct, which must be an integral multiple of the latter.
For example:
1#include <stdio.h>2typedefstructTest {3 Charname[ -];4 intWord;5 Charbit;6 DoubleNumber ;7 ShortAge ;8 9 } mix;Ten One intMain () { A mix Hello; - intn =sizeof(n); -printf"%d \ n", n);//The result is a the return 0; -}
As we have expected, the result is a, well, how could we get it? Now let us explain it:
Split-Step parsing:
1:NAME[18], Bytes 0-18->20
2:word, 4 bytes 20-24
3:bit, 1 bytes 24-25->32
4:number, 8 bytes 32-40
5:age, 2 bytes 40-42
6: The maximum number of bytes is 8 (the array is a char type, the number of bytes is 1), and the last struct body length is an integer multiple of the maximum number of bytes, so the complement to 48
A small analysis of the structure body storage