Understanding memory alignment in Rust on 32-bit targets
This is a medium-difficulty systems programming question that tests your grasp of how Rust handles struct layout and memory alignment across different target architectures. It's the kind of problem that surfaces in roles requiring low-level code — embedded systems, high-performance libraries, or kernel-adjacent work — where assumptions about data layout can silently break correctness or performance.
To work through it, you need to reason about how the Rust compiler pads and aligns struct fields on a 32-bit platform, how that affects the size and memory addresses of members, and what that means for the runtime output of the program. Release-mode compilation matters because it may enable optimizations that change observable behaviour. The question rewards precision: vague answers about "alignment happens" won't suffice.
- Struct field ordering and compiler padding
- Size and alignment requirements for primitive types on 32-bit vs. 64-bit
- How
repr attributes control layout - Target-specific compilation and cross-architecture reasoning