The alignment rule (on x86 and x86_64), as a rule, should align the variable to its size.
In other words, 32-bit variables are aligned by 4 bytes, 64-bit variables by 8 bytes, etc.
The offset f is 12, so in the case of uint32_t f padding is not required, but when f is uint64_t , 4 padding bytes are added to get f to align by 8 bytes.
For this reason, it is better to arrange data items from largest to smallest . Then there would be no need for filling or packaging.
source share