Memory alignment in C-structs
问题 I'm working on the 32-bit machine, so I suppose that memory alignment should be 4 bytes. Say I have struct: typedef struct { unsigned short v1; unsigned short v2; unsigned short v3; } myStruct; the real size is 6 bytes, and I suppose that aligned size should be 8, but sizeof(myStruct) returns me 6. However if I write: typedef struct { unsigned short v1; unsigned short v2; unsigned short v3; int i; } myStruct; the real size is 10 bytes, aligned is 12, and this time sizeof(myStruct) == 12 . Can