The worst possible Hello World program
boredzo.org
boredzo.org
% 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.
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.
I'll fix it in a few minutes.
If they're both not writable, or stderr is writable but writing fails anyway, there's nothing we can do about it anyway, but that does not make it any less proper to try.
And dude, don't go using the word 'worst' as lightly as that. It's dangerous - I am sure we could make it ohhh really quite worse... how about relying on some known compiler/os bugs to flip some bits somewhere, obfuscating it right up then generate some code by repeating various pointless operations (but all slightly subtly randomly different so not obvious enough to remove) to get it to say ~ 5 million lines of code? :-D
Honestly, if I were writing this today, I'd make the “worst” example less bad. What you see here is way too fantastic. 2011 Me would make it realistically bad—the sort of thing a new or just plain apathetic programmer might write. I wonder, though, how much it would differ from the canonical one-liner.
In a few days, if I don't forget, I'll appoint whatever the page and samples look like by then as 1.0. Leaving things pre-1.0 bugs me more now than it did back when I originally published this.
The result of this is that I always use fputs to write a plain C string to a stdio handle, specifying stdout explicitly and adding newlines if needed, and I ignore puts entirely, much like I ignore gets. The convenience is not worth the subtle error-causing asymmetry and associated mnemonic pain, especially if that code may ever have to write somewhere other than stdout.
I don't see how "does not try to insert any values into the string" and "supplies the terminating newline" are not contradictory.