It is clear from the reference manual that the memory layout of struct
s is unspecified (when the repr
attribute is not used). This rule gives the compiler the possibility to pack structures tighter by reordering the fields.
What about the memory layout of tuples and tuple structs? How is it (un)specified and why?
The memory layout of tuples and tuple structs is undefined, just like the layout of normal structs, with one exception:
The exception to this is the unit tuple (
()
) which is guaranteed as a zero-sized type to have a size of 0 and an alignment of 1.
The compiler can make the same optimizations in tuples and tuple structs that it can in structs, it just has to re-order matches of them as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With