File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 13
13
union U { f1: T1, f2: T2 }
14
14
```
15
15
16
- is to determine the offset of the fields. The layout of these fields themselves
16
+ is to determine the offset of the fields. The layout of these fields themselves
17
17
is already entirely determined by their types, and since we intend to allow
18
18
creating references to fields (` &u.f1 ` ), unions do not have any wiggle-room
19
19
there.
@@ -42,8 +42,11 @@ to obtain a pointer to any field, and vice versa.
42
42
#### Padding
43
43
44
44
Since all fields are at offset 0, ` repr(C) ` unions do not have padding before
45
- their fields. They can, however, have trailing padding, to make sure the size is
46
- a multiple of the alignment:
45
+ their fields. They can, however, have padding in each union variant * after* the
46
+ field, to make all variants have the same size.
47
+
48
+ Moreover, the entire union can have trailing padding, to make sure the size is a
49
+ multiple of the alignment:
47
50
48
51
``` rust
49
52
# use std :: mem :: {size_of, align_of};
You can’t perform that action at this time.
0 commit comments