Skip to content

Commit 5e68de3

Browse files
authored
Merge pull request #1493 from kpreid/patch-1
Expand and clarify primitive alignment
2 parents 735c5db + a432cf4 commit 5e68de3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/type-layout.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,20 @@ The size of most primitives is given in this table.
4444
| `u32` / `i32` | 4 |
4545
| `u64` / `i64` | 8 |
4646
| `u128` / `i128` | 16 |
47+
| `usize` / `isize` | See below |
4748
| `f32` | 4 |
4849
| `f64` | 8 |
4950
| `char` | 4 |
5051

5152
`usize` and `isize` have a size big enough to contain every address on the
52-
target platform. For example, on a 32 bit target, this is 4 bytes and on a 64
53+
target platform. For example, on a 32 bit target, this is 4 bytes, and on a 64
5354
bit target, this is 8 bytes.
5455

55-
Most primitives are generally aligned to their size, although this is
56-
platform-specific behavior. In particular, on many 32-bit platforms `u64`
57-
and `f64` are only aligned to 32 bits.
56+
The alignment of primitives is platform-specific.
57+
In most cases, their alignment is equal to their size, but it may be less.
58+
In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though
59+
their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only
60+
aligned to 4 bytes, not 8.
5861

5962
## Pointers and References Layout
6063

0 commit comments

Comments
 (0)