News for hackers. Stuff that matters.
Re:The worst possible Hello World program by mturmon on Sunday April 03, 2011 @03:37AM (#2402078)
This is actually quite a laugh. Compiling the author's recommended "best" hello world on Mac OS 10.6 (gcc 4.2.1) yields this:

    % a.out
    Hello World!
    ERROR: fputs did not succeed in writing our message string (error returned: Unknown error: 0)!
A look at the man page for puts shows that the author bungled the test for error:

fputs() now returns a non-negative number (as opposed to 0) on successful completion. As a result, many tests (e.g., "fputs() == 0", "fputs() != 0") do not give the desired result. Use "fputs() != EOF" or "fputs() == EOF" to determine success or failure.

That's the price for over-engineering.

Re:The worst possible Hello World program by boredzo on Sunday April 03, 2011 @03:53AM (#2402109)
Not so much bungled as got bitten by a change in behavior. Amusingly, “Return Values” still states the old behavior, to which standard the program is correct.

I'll fix the program.

By the way, the zip archives include a Makefile with correct compiler configuration (namely -std=c99). I tried downloading them after seeing this thread and it didn't work; I've re-uploaded them and now they download correctly, Makefiles and all. No more having to run the compiler by hand.

Re:The worst possible Hello World program by singular on Sunday April 03, 2011 @03:41AM (#2402087)
Ouch. Now the article isn't just advocating overengineering, it's just plain wrong - have you contacted the author to let him know? Probably best for him to fix this up asap.
Re:The worst possible Hello World program by boredzo on Sunday April 03, 2011 @03:45AM (#2402097)
mturmon hasn't (so far), but a friend just passed me the link to this thread. Thanks nonetheless.

I'll fix it in a few minutes.

Re:The worst possible Hello World program by singular on Sunday April 03, 2011 @03:55AM (#2402116)
And I hope all this criticism isn't too down-heartening... at least from my part (though I strongly believe it is the same for others too) it's intended as friendly and genuine constructive criticism.
Re:The worst possible Hello World program by boredzo on Sunday April 03, 2011 @04:15AM (#2402150)
Not at all. I always welcome constructive criticism; any opportunity to improve myself, I much appreciate. For my part, any criticism I offer, including the linked article itself, I likewise intend to be constructive.
Re:The worst possible Hello World program by mturmon on Sunday April 03, 2011 @03:50AM (#2402106)
BTW, I got the string "Hello Worldp" from the first program, using the same compiler configuration. I had to use std=c99 to get it to compile (the variable in the for loop).