It's just that there is a compile time optimisation that allows the compiler to assume you will never read from uninitialised memory.
It would be perfectly possible to make a language (or even a C++ compiler) that didn't perform that optimisation.
It's just that there is a compile time optimisation that allows the compiler to assume you will never read from uninitialised memory.
It would be perfectly possible to make a language (or even a C++ compiler) that didn't perform that optimisation.
No it's not. To describe the behavior of a program involving uninitialized memory (like the example in my post), at no point in time to you need to talk about arbitrarily chosen bytes. The "abstract machine" on which a Rust programs runs (of which your hardware is a fast implementation, but only accurate for UB-free programs) does not "pick random bytes" when you allocate new memory, it just fills it all with `None`.
You should not think in terms of optimizations when thinking about what your program does. The optimizations the compiler performs can change from version to version and are affected by seemingly random changes at the other end of your program.
> It would be perfectly possible to make a language (or even a C++ compiler) that didn't perform that optimisation.
Sure. That would be a different language though, with a different abstract machine. C/C++/Rust behave the way I described (and that behavior is not defined by what any particular compiler does).
Think about assembly. What is uninitialised memory there? It's just memory with an unknown value.