Structure alignment padding, largest size of padding, and order of struct members
I've been learning about structure data padding since I found out my sizeof() operator wasn't returning what I expected. According to the pattern that I've observed, it aligns structure members with the largest data type. So for example... struct MyStruct1 { char a; // 1 byte char b; // 1 byte char c; // 1 byte char d; // 1 byte char e; // 1 byte // Total 5 Bytes //Total size of struct = 5 (no padding) }; struct MyStruct2 { char a; // 1 byte char b; // 1 byte char c; // 1 byte char d; // 1 byte char e; // 1 byte short f; // 2 bytes // Total 7 Bytes //Total size of struct = 8 (1 byte of padding