Re:Obfuscated Game of Life in 9 lines of C
by CJefferson on Saturday November 30, 2013 @05:10AM
(#6822775)
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.
Re:Obfuscated Game of Life in 9 lines of C
by babuskov on Monday December 02, 2013 @08:04AM
(#6833343)
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.
Re:Obfuscated Game of Life in 9 lines of C
by twoodfin on Monday December 02, 2013 @04:24PM
(#6836624)
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:
http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
Re:Obfuscated Game of Life in 9 lines of C
by babuskov on Tuesday December 03, 2013 @11:38AM
(#6841311)
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?
Re:Obfuscated Game of Life in 9 lines of C
by foxhill on Saturday November 30, 2013 @10:17AM
(#6823332)
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.
then it's ~__+__
so
You can see how that always works.