[rust-dev] Alignment and tuples

Niko Matsakis niko at alum.mit.edu
Thu Apr 12 06:49:23 PDT 2012


On 4/12/12 6:15 AM, Alexander Stavonin wrote:
> type tuple_type1 = (u64, u32, u16);
> type tuple_type2 = (u8, u32, u16);
>
> ...
>
> size of tuple_type1 = 16, size of typle_type2 = 12
> align of tuple_type1 = 8, align of tuple_type2 = 8
>
> I expected same size for tuple_type1 and tuple_type2 in case of alignment 8. Or tuple_type2  have alignment 4, but align_of returns invalid result?

The alignment refers to the alignment of the overall structure.  The 
internal components do not all share the same alignment.  To be honest, 
though, I am not sure why the alignment of tuple_type2 is listed as `8`, 
that seems like a bug.  I would expect 4 and a size of 12.


Niko


More information about the Rust-dev mailing list