Skip to content

Commit ec33e2b

Browse files
author
Benjamin Herr
committed
Address to pointer cast: hint at provenance.
1 parent d65e590 commit ec33e2b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/expressions/operator-expr.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,11 @@ Here `*T` means either `*const T` or `*mut T`.
361361
* `u8` to `char` cast
362362
* Casts to the `char` with the corresponding code point.
363363
* Pointer to address cast
364-
* Casting from a valid raw pointer to `usize` will produce a numeric address representing the pointer.
364+
* Casting from a valid raw pointer to `usize` will produce the address that is pointed to. Note that the pointer's provenance is lost in this conversion.
365365
* Address to pointer cast
366-
* Casting from `usize` to a raw pointer will produce a pointer with the same value as the original pointer if the `usize` was obtained through a pointer to address cast of a valid pointer of the same type.
366+
* Casting from `usize` to a raw pointer will produce a raw pointer to the same location as the original pointer, if the `usize` was obtained through a pointer to address cast of a valid pointer.
367+
368+
Note that the two pointers are not equivalent. Dereferencing the pointer obtained from the address to pointer cast may be [undefined behavior] if aliasing rules are not followed.
367369

368370
\* if integer-to-float casts with this rounding mode and overflow behavior are
369371
not supported natively by the hardware, these casts will likely be slower than
@@ -377,6 +379,8 @@ expected.
377379
number, preferring the one with an even least significant digit if exactly
378380
halfway between two floating point numbers.
379381

382+
[undefined behavior]: ../behavior-considered-undefined.md
383+
380384
## Assignment expressions
381385

382386
> **<sup>Syntax</sup>**\

0 commit comments

Comments
 (0)