News for hackers. Stuff that matters.
Re:Both true and false: a Zen moment with C by defrost on Wednesday June 27, 2012 @10:46AM (#4167193)
Interestingly, . . . it's a pointless exercise delving into ASM to "see what happens" when you have undefined behaviour in C code. A slight flag change and the only code produced could equally well just be a single NOP.
Re:Both true and false: a Zen moment with C by simias on Wednesday June 27, 2012 @10:53AM (#4167260)
Still, gcc is a pretty serious piece of software (no more starting nethack these days), so while the behaviour is undefined it's still interesting to see why the compiler ended up generating a code that behaves so weirdly.

If you need to find a use for it, it might make it easier to spot an undefined behaviour later and finding its cause ("hey, this evalutates both to true and false, it must be an unitialized bool!").

So it's still interesting and might not be completely pointless.

Re:Both true and false: a Zen moment with C by defrost on Wednesday June 27, 2012 @12:12PM (#4167669)
LLVM is more interesting piece of software, gcc is kind of crusty and warty.

Still, I'm glad you're interested in the language, if you're interested in undefined behaviour then you should carefully and closely read the latest free draft standard (N1570) and perhaps implement a small C compiler of your own ( Appel : Modern Compiler Implementation ).

There are many C compilers, they are free to do whatever they want when behaviour is undefined and in many cases you'll unfortunately not see anything odd at all, not until you port your code, change your flags or upgrade the compiler and then you'll having a seething mass of "well this stuff worked when we tested it" errors.

Strapping yourself into a vehicle and driving off a cliff teaches you a little about the dangers of accidents and gives you a reason to drive safely, it doesn't particularly teach much about the practice of safe driving.

The example code drove off the road, what happened next really isn't all that exciting.

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

http://www.cs.princeton.edu/~appel/modern/c/

Re:Both true and false: a Zen moment with C by dllthomas on Wednesday June 27, 2012 @04:56PM (#4169222)
Many serious pieces of software are crusty and warty.
Re:Both true and false: a Zen moment with C by Niten on Wednesday June 27, 2012 @11:04AM (#4167333)
shrug I do think it's interesting to find out, in concrete terms, the sort of real-world assumptions that a compiler might make, which make C's undefined behavior what it is. Yes, pointless in terms of fixing the actual program, though... to each his own :)
Re:Both true and false: a Zen moment with C by mikeash on Wednesday June 27, 2012 @11:05AM (#4167343)
It's not pointless at all. Yes, you can't rely on the output being that way all the time, but it still teaches you about the compiler, the language implementation, and the CPU architecture to investigate this stuff.