...
Here, the compiler could implement arg.b = 2 in the following way,:
- setting the low byte of a 32-bit register to 2, leaving the high bytes unchanged, and
- storing all 32 bits of the register into memory,
...
GCC allows specifying attributes of variables and structures using the keyword __attribute__((__packed__)). This means that the GCC will not add any padding bytes (for memory alignment) and will make variables or fields immediately next to each other.
...
For example, in an IA-32 machine, the explicit insertion of the padding bytes into the struct should ensure that no "invisible" padding bytes are added in by the compiler, and consequently the expression in static_assert should be true.
...
However, if you were compiling for a different architecture and the compiler adds added padding bytes, then the memory would not be contiguous and the expression would return 0.
...
| [ISO/IEC 9899:2011] | Section 6.2.6.1, "General" (para. 6) |
|---|