News for hackers. Stuff that matters.
Re:“What the Hardware Does” Is Not What Your Program Does: U... by IshKebab on Monday July 15, 2019 @06:27AM (#20439457)
I don't think this is really right. He claims that uninitialised memory is not just random bytes, but it is!

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.

Re:“What the Hardware Does” Is Not What Your Program Does: U... by ralfjung on Monday July 15, 2019 @07:58AM (#20439953)
> I don't think this is really right. He claims that uninitialised memory is not just random bytes, but it is!

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).

Re:“What the Hardware Does” Is Not What Your Program Does: U... by IshKebab on Wednesday July 17, 2019 @11:26AM (#20460474)
You missed my point. Rust and C may treat uninitialised memory in a special way, but that doesn't change what uninitialised memory actually is.

Think about assembly. What is uninitialised memory there? It's just memory with an unknown value.