@@ -119,7 +119,7 @@ representations can be applied to a single type.
119
119
The representation of a type can be changed by applying the ` repr ` attribute
120
120
to it. The following example shows a struct with a ` C ` representation.
121
121
122
- ```
122
+ ``` rust
123
123
#[repr(C )]
124
124
struct ThreeInts {
125
125
first : i16 ,
@@ -148,7 +148,7 @@ There are no guarantees of data layout made by this representation.
148
148
149
149
The ` C ` representation is designed for dual purposes. One purpose is for
150
150
creating types that are interoperable with the C Language. The second purpose is
151
- to create types that you can soundly performing operations that rely on data
151
+ to create types that you can soundly perform operations on that rely on data
152
152
layout such as reinterpreting values as a different type.
153
153
154
154
Because of this dual purpose, it is possible to create types that are not useful
@@ -205,7 +205,7 @@ The union will have a size of the maximum size of all of its fields rounded to
205
205
its alignment, and an alignment of the maximum alignment of all of its fields.
206
206
These maximums may come from different fields.
207
207
208
- ```
208
+ ``` rust
209
209
#[repr(C )]
210
210
union Union {
211
211
f1 : u16 ,
@@ -280,19 +280,29 @@ The `align` representation can be used on `struct`s and `union`s to raise the
280
280
alignment of the type to a given value.
281
281
282
282
Alignment is specified as a parameter in the form of ` #[repr(align(x))] ` . The
283
- alignment value must be a power of two of type ` u32 ` . The ` align ` representation
284
- can raise the alignment of a type to be greater than it's primitive alignment,
285
- it cannot lower the alignment of a type.
283
+ alignment value must be a power of two up to 2< sup >29</ sup > . The ` align `
284
+ representation can raise the alignment of a type to be greater than it's
285
+ primitive alignment, it cannot lower the alignment of a type.
286
286
287
287
The ` align ` and ` packed ` representations cannot be applied on the same type and
288
288
a ` packed ` type cannot transitively contain another ` align ` ed type.
289
289
290
290
### The ` packed ` Representation
291
291
292
- The ` packed ` representation can only be used on ` struct ` s and ` union ` s.
292
+ The ` packed ` representation can be used on ` struct ` s and ` union ` s to lower the
293
+ alignment and padding of the type.
294
+
295
+ The packing value is specified as a parameter in the form of
296
+ ` #[repr(packed(x))] ` . If no value is given, as in ` #[repr(packed)] ` , then the
297
+ packing value is 1. The packing value must be a power of two up to
298
+ 2<sup >29</sup >.
293
299
294
- It modifies the representation (either the default or ` C ` ) by removing any
295
- padding bytes and forcing the alignment of the type to ` 1 ` .
300
+ The ` packed ` representation sets the alignment to the smaller of the specified
301
+ packing and the current alignment (either default or ` C ` ). The alignments of
302
+ each field for the purpose of positioning fields would also be the smaller of
303
+ the specified packing and the alignment of the type of that field. If the
304
+ specified packing is greater than or equal to the default alignment of the
305
+ type, then the alignment and layout is unaffected.
296
306
297
307
The ` align ` and ` packed ` representations cannot be applied on the same type and
298
308
a ` packed ` type cannot transitively contain another ` align ` ed type.
0 commit comments