|
1 |
| -# Layout of Boolean, Floating Point, and Integral Types |
| 1 | +# Layout of scalar types |
2 | 2 |
|
3 | 3 | This chapter represents the consensus from issue [#9]. It documents the memory
|
4 |
| -layout and considerations for `bool`, floating point types (`f{32, 64}`), and |
5 |
| -integral types (`{i,u}{8,16,32,64,128,size}`). |
| 4 | +layout and considerations for `bool`, `char`, floating point types (`f{32, 64}`), and integral types (`{i,u}{8,16,32,64,128,size}`). |
6 | 5 |
|
7 | 6 | These types are all scalar types, representing a single value, and have no
|
8 | 7 | layout `#[repr()]` flags.
|
@@ -48,22 +47,10 @@ The layout of `usize` determines the following:
|
48 | 47 | - the maximum number of elements in an array (`[T; N: usize]`),
|
49 | 48 | - how much a pointer of a certain type can be offseted (limited by `usize::max_value()`).
|
50 | 49 |
|
51 |
| -> **FIXME**: Pointer `add` operates on `usize`, but pointer `offset` operates on |
52 |
| -> `isize`, so unless by "offseted" we mean something different from `ptr.offset` |
53 |
| -> above, `usize::max_value()` does not determine how much a pointer can be |
54 |
| -> "offseted". We should probably be more specific here and call out `ptr.add` |
55 |
| -> and `ptr.offset` explicitly. |
56 |
| -
|
57 | 50 | The maximum size of any single value must fit within `usize` to [ensure that
|
58 | 51 | pointer diff is
|
59 | 52 | representable](https://github.com/rust-rfcs/unsafe-code-guidelines/pull/5#discussion_r212703192).
|
60 | 53 |
|
61 |
| -> **FIXME**: This does not make sense. We state that the layout of `usize` |
62 |
| -> determines the maximum size of an object, and then argue that this is to |
63 |
| -> ensure that pointer diff is representable, which won't be the case if the size |
64 |
| -> of an object is `usize::max_val()`. The link cited actually states that, right |
65 |
| -> now, the largest size of a Rust object is limited by `isize::max_value()`. |
66 |
| -
|
67 | 54 | [pointer types]: ./pointers.md
|
68 | 55 |
|
69 | 56 | ## Fixed-width integer types
|
|
0 commit comments