Start with the idea
Rust's default layout may change for optimization and is not an FFI contract. repr(C) gives C-compatible field ordering while fixed integer types make sizes explicit.
Rust's default struct representation is chosen for Rust code, not as an external wire or ABI contract. #[repr(C)] requests C-compatible field ordering and layout rules for the target, including padding between fields. It does not make a struct packed, remove padding, or guarantee the same total size on every architecture. Fixed-width fields such as u16 and u32 make individual sizes explicit, but alignment and endianness still matter when bytes cross a file or network boundary.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.