Every scalar type has an alignment, equal to its size on x86-64 (a double starts at a multiple of 8). The compiler lays out a structure’s fields in declaration order and inserts structure padding, unused bytes, before any field that would otherwise be misaligned and at the end, so that the structure’s size is a multiple of its largest alignment.
Voorbeelden
Example 6.2 (Ordering fields)
An order written as a first draft declares a char side, a double price, a char flag, a 64-bit id, a 32-bit quantity and a char time in force: 23 bytes of data in 40 bytes, 17 of them padding. Ordered by size (id, price, quantity, then the three characters) the same fields take 24 bytes: eight orders occupy three 64-byte cache lines instead of five. The compiler will not reorder fields itself: the order is part of the type’s interface.