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
All runtime-allocated memory in a Rust program begins its life as uninitialized. In this state the value of the memory is an indeterminate pile of bits that may or may not even reflect a valid state for the type that is supposed to inhabit that location of memory. Attempting to interpret this memory as a value of any type will cause Undefined Behavior.
That's not true; there are types that allow reading a value from uninitialized memory for some or all of their bytes: MaybeUninit is the obvious example, and more generally unions with a () field (or even all unions, details are TBD). Also, padding bytes are allowed to be uninitialized.
The text was updated successfully, but these errors were encountered:
RalfJung
changed the title
"Working With Uninitialized Memory" makes voerly broad claims
"Working With Uninitialized Memory" makes overly broad claims
Dec 12, 2023
Here, the Nomicon claims
That's not true; there are types that allow reading a value from uninitialized memory for some or all of their bytes:
MaybeUninit
is the obvious example, and more generally unions with a()
field (or even all unions, details are TBD). Also, padding bytes are allowed to be uninitialized.The text was updated successfully, but these errors were encountered: