You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `align` and `packed` modifiers can be used to respectively raise or lower the alignment of `struct`s and `union`s. `packed` may also alter the padding between fields (although it will not alter the padding inside of any field). On their own, `align` and `packed` do not provide guarantees about the order of fields in the layout of a struct or the layout of an enum variant, although they may be combined with representations (such as `C`) which do provide such guarantees.
497
479
480
+
> [!EXAMPLE]
481
+
> ```rust
482
+
> // Default representation, alignment lowered to 2.
483
+
> #[repr(packed(2))]
484
+
> structPackedStruct {
485
+
> first:i16,
486
+
> second:i8,
487
+
> third:i32
488
+
> }
489
+
>
490
+
> // C representation, alignment raised to 8
491
+
> #[repr(C, align(8))]
492
+
> structAlignedStruct {
493
+
> first:i16,
494
+
> second:i8,
495
+
> third:i32
496
+
> }
497
+
> ```
498
+
498
499
r[layout.repr.alignment.constraint-alignment]
499
500
Thealignmentisspecifiedasanintegerparameterintheformof `#[repr(align(x))]` or `#[repr(packed(x))]`.Thealignmentvaluemustbeapoweroftwofrom1upto2<sup>29</sup>.For `packed`, ifnovalueisgiven, asin `#[repr(packed)]`, thenthevalueis1.
0 commit comments