Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cead255

Browse files
authoredMar 17, 2025··
Mention that “every address” ≠ “every pointer”
This adds a note in case people are tempted to interpret “`usize` ... can represent every memory address” as saying that pointer→usize→pointer roundtrips are definitely okay. Since the reference does not yet discuss provenance and that’s a much larger matter, I have merely linked to relevant existing documentation inside and outside the reference.
1 parent dda31c8 commit cead255

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
 

‎src/types/numeric.md

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ r[type.numeric.int.size.usize]
4040
The `usize` type is an unsigned integer type with the same number of bits as the
4141
platform's pointer type. It can represent every memory address in the process.
4242

43+
> [!NOTE]
44+
> While a `usize` can represent every *address*, converting a *pointer* to a `usize` is not necessarily a reversible operation.
45+
> For more information, see the documentation for [type cast expressions] and [`std::ptr`].
46+
4347
r[type.numeric.int.size.isize]
4448
The `isize` type is a signed integer type with the same number of bits as the
4549
platform's pointer type. The theoretical upper bound on object and array size
@@ -58,3 +62,5 @@ r[type.numeric.validity]
5862

5963
For every numeric type, `T`, the bit validity of `T` is equivalent to the bit
6064
validity of `[u8; size_of::<T>()]`. An uninitialized byte is not a valid `u8`.
65+
66+
[type cast expressions]: ../operator-expr.html#type-cast-expressions

0 commit comments

Comments
 (0)
Please sign in to comment.