Live data from Hacker News

The worst possible Hello World program

boredzo.org

1–10 of 23 posts

Re: The worst possible Hello World program

#2
I get the point, and it's important to point out to beginners the various subtleties of error checking, etc. - but to me the 'best possible' hello world is rather overengineered, I mean 4 includes to begin with... :-)

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

Re: The worst possible Hello World program

#4
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

#5
post #4

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 resul…

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

#6
post #5
post #4

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 resul…

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.

[deleted]

Re: The worst possible Hello World program

#7
post #5
post #4

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 resul…

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.

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

#8
post #7
post #5

Earlier quoted context omitted.

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.

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.

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).

Re: The worst possible Hello World program

#9
post #4

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 resul…

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

#10
We now use puts instead of printf. puts does not try to insert any values into the string, and it supplies the terminating newline (the \n you saw before) for us.

I don't see how "does not try to insert any values into the string" and "supplies the terminating newline" are not contradictory.

Post reply on HN