[rust-dev] Alignment and tuples

Alexander Stavonin a.stavonin at gmail.com
Thu Apr 12 06:15:42 PDT 2012

I'm confused, how it is possible?

type tuple_type1 = (u64, u32, u16);
type tuple_type2 = (u8, u32, u16);

fn main() {
    io::println(#fmt("size of tuple_type1 = %u, size of tuple_type2 = %u",
        sys::size_of::<tuple_type1>(), sys::size_of::<tuple_type2>()));
    io::println(#fmt("align of tuple_type1 = %u, align of tuple_type2 = %u",
        sys::align_of::<tuple_type1>(), sys::align_of::<tuple_type2>()));


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?

More information about the Rust-dev mailing list