You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/operator-expr.md
+20-6Lines changed: 20 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -380,20 +380,34 @@ Casts an enum to its discriminant, then uses a numeric cast if needed.
380
380
381
381
#### Pointer to address cast
382
382
383
-
Casting from a valid raw pointer to `usize` will produce the address that is pointed to.
384
-
385
-
The pointer's provenance is lost in this conversion.
383
+
Casting from a raw pointer to an integer produces the machine address of the referenced memory.
384
+
If the integer type is smaller than the pointer type, the address may be truncated; using `usize` avoids this.
386
385
387
386
#### Address to pointer cast
388
387
389
-
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.
388
+
Casting from an integer to a raw pointer interprets the integer as a memory address and produces a pointer referencing that memory.
390
389
391
390
<divclass="warning">
392
391
Warning:
393
-
The two pointers are not equivalent.
394
-
Dereferencing the pointer obtained from the address to pointer cast may be <ahref="../behavior-considered-undefined.md">undefined behavior</a> if aliasing rules are not followed.
392
+
This interacts with the Rust memory model, which is still under development.
393
+
A pointer obtained from this cast may suffer additional restrictions even if it is bitwise equal to a valid pointer.
394
+
Dereferencing such a pointer may be <ahref="../behavior-considered-undefined.md">undefined behavior</a> if aliasing rules are not followed.
0 commit comments