News for hackers. Stuff that matters.
Re:Obfuscated Game of Life in 9 lines of C by twoodfin on Friday November 29, 2013 @09:54PM (#6822066)
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 __.
Re:Obfuscated Game of Life in 9 lines of C by babuskov on Friday November 29, 2013 @10:06PM (#6822091)
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.
Re:Obfuscated Game of Life in 9 lines of C by Madrigal on Saturday November 30, 2013 @10:40AM (#6823390)
Yes, it is undefined behavior by the standard, but most compilers will give you some random value and you will get the answer that GhotiFish states.
Re:Obfuscated Game of Life in 9 lines of C by GhotiFish on Saturday November 30, 2013 @03:23AM (#6822630)
lets say __ is 0x00101101

then it's ~__+__

so

   0x00101101
  +0x11010010
You can see how that always works.
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.