Use "pictures" to explain degrees of freedom in struct and union layout #185
Labels
A-layout
Topic: Related to data structure layout (`#[repr]`)
C-editorial
Category: Tracking editorial improvements to the document
In #160 (comment) I suggested to use "pictures" to explain what happens when a
struct
/union
is laid out (at least in terms of size and field offsets) and how we call the movable pieces there.For structs:
This shows we can have leading, inner, and trailing "padding".
For unions:
This shows that for each field/variant, we can have (separate) leading and trailing padding.
I think it would be nice to incorporate this into the document. But for this we basically need consensus that how big the padding is and (only for structs) in which order the fields come is the only freedom the compiler has to lay out these types. I am pretty sure that's true, e.g. we cannot split a field because you can take a reference to a field and that has to be using the layout of the type of that field -- but better safe than sorry. ;)
The text was updated successfully, but these errors were encountered: