Isn't reading an uninitialized variable that could have been given a "register" qualifier undefined behavior? That is, the program never takes the address of __.
In most cases, a program would just read from "dirty" memory and you might get a random value. In this case, whatever bits are there, they "add up" to -1, so it just works.
Unfortunately not. When you have not written to a C variable, it doesn't have a random value, reading it is undefined. Different reads can produce different values.
Not really. When you declare a variable the system assigns it an address on stack. When you try to read it, it reads the value currently stored at that address. Subsequent reads all read from the same address.
Unless you have something else writing to this address, the value will not change. Since the program's stack is only available to that program, it will stay the same.
Yes, really. I don't think you understand the leeway that C/C++ give implementations when they encounter undefined behavior. Your mental model of how the code "should" be compiled can go out the window when an optimizer designed to work properly only on well-defined code goes to work:
I'm sorry, but nothing in that article contradicts what I wrote. I wrote that once variable is declared, a memory location is assigned to it and this location nor it's content change over time, unless you write to (initialize) it yourself.
Care to quote the sentence(s) that say differently?
as you said, reading it is just undefined. the compiler has to do something, and it's improbable that a read before write, followed by another read will result in two different values.
if you could produce a piece of code that exhibits the behaviour you describe, i'd very much like to see it.
I'm sure many would complain about the obfuscated nature of the code. I however find it strangly beautiful. It has the appearance of a strand of DNA and then one marvels at all of the complexity hidden in these cryptic lines.
That's old. Nowadays, it would only be impressive if it were written in pure CSS.
Yes, that's a snark, but also a challenge to those with time on their hands. Bonus points if your solution grows the universe to contain, e.g., an escaping glider.
Apparently, it is: https://github.com/elitheeli/stupid-machines (I haven't taken the time to check that, but take it that 'the internet' would have corrected this by now if it weren't true)