Memory allocation of structures in C / C language
When the interlocking number of the compiler is not specified with the #pragma instruction, the structure is aligned in the width of the data member of the longest width; when the #pragma instruction specifies the number of alignment bits of the compiler, the structure is pressed by the longest width. The smaller value aligned in the width of the data member and the number of bits specified by the #pragma directive. The #pragma instruction format is as follows: #pragma pack (4) // or #pragma pack (push, 4) is as follows: (machine word length is 32 bits) struct {char A;} test; printf ("% D / n ", sizeof test); the result of printing is 1; struct {char A; short b; char C;} test; printf ("% d / n ", sizeof test); printed result is 6; struct { Char A; int b; char C;} test; printf ("% d / n", sizeof test); printed results 12; struct {char A; double b; char C;} test; printf ("% D / N ", SIZEOF TEST; printed result is 24; #pragma Pack (4) struct {char A; double b; char C;} test; printf ("% d / n ", sizeof test); print The result is 16; reference: 1. http://sci.ustc.edu.cn/news.aspx?id=55772. "Computer System Structure", Third Edition, Li Xuelie Edited, Xi'an University of Electronic Science and Technology Press, June 3, 2000.
Big character sequence small word sequence