Re:The Lost Art of C Structure Packing (2014)
by dbaupp on Friday August 05, 2016 @04:21PM
(#12235479)
Rust doesn't ignore field size nor does it align to any particular boundary. E.g. struct Foo { x: u8 } is one byte and has alignment 1, and similarly struct Bar { x: u8, y: i16 } is 4 bytes and has alignment 2. The compiler doesn't give guarantees about structure layout so that it is able to reduce the size by reordering fields.
[ Parent
| on HN ]
Re:The Lost Art of C Structure Packing (2014)
by valarauca1 on Friday August 05, 2016 @06:31PM
(#12236141)
So the nomicon is out of date?
It says Struct fields are aligned to to the 32/64bit boundary based on system architecture. Then you have #[repr(u8/u16/u32/u64)] which will align to 8/16/32/64 boundary.
Re:The Lost Art of C Structure Packing (2014)
by Gankro on Friday August 05, 2016 @06:57PM
(#12236244)
No you're just making stuff up.
https://doc.rust-lang.org/nomicon/repr-rust.html
The bulk of this section is describing how Rust has reserved the right to reorder and pack stuff. The first example happens to be 32-bit aligned because it contains a value that is.