Yes, it can affect it. In the first given example, all of the fields can fit into a single 64-bit uint64-t
, so the structure likely takes 8 bytes total. With the second, though, it would likely be 16 bytes total. The first three fields would require at least two bytes (two uint8_t
). Then the last bit field of 55 bits would take a single uint64_t
which would likely be aligned on an 8 byte boundary. So while the actual layout is compiler-dependent, the position of the bits would be different in both examples (because of the assumed padding prior to the uint64_t
in the second example.
The layout would likely be something like the following (not exactly to scale):
bf_struct1
+---------------+---------+---------+-----------------------------------+
| uint8_t | uint8_t | Padding | uint64_t |
+---------------+---------+---------+-----------------------------------+
| bf1, bf2, bf3 | 48-bits | bf4 |
+---------------+---------+---------+-----------------------------------+
bf_struct2
+-----------------------------------+
| uint64_t |
+-----------------------------------+
| bf1, bf2, bf3, bf4 |
+-----------------------------------+