Skip to content

Commit d46db14

Browse files
authored
Clarify guarantees provided by repr(packed)
Clarify that `repr(packed)` minimizes inter-field padding and, in the special case of `repr(packed(1))`/`repr(packed)`, guarantees no inter-field padding.
1 parent 039e1a7 commit d46db14

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/type-layout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@ For `packed`, if the specified alignment is greater than the type's alignment
515515
without the `packed` modifier, then the alignment and layout is unaffected.
516516
The alignments of each field, for the purpose of positioning fields, is the
517517
smaller of the specified alignment and the alignment of the field's type.
518+
Inter-field padding is guaranteed to be the minimum required in order to
519+
satisfy each field's (possibly altered) alignment (although note that, on its
520+
own, `packed` does not provide any guarantee about field ordering). An
521+
important special case is `#[repr(packed(1))]` (or `#[repr(packed)]`), which
522+
guarantees that no inter-field padding will be present.
518523

519524
The `align` and `packed` modifiers cannot be applied on the same type and a
520525
`packed` type cannot transitively contain another `align`ed type. `align` and

0 commit comments

Comments
 (0)