RT @Sunfishcode: Finding bugs in Hello World tutorial programs

Emotional, Burning, Unlimited Tuned Laboratory

Bugs in Hello World
Posted on March 08, 2022

Hello World might be the most frequently written computer program. For decades, it’s been the first program many people write, when getting started in a new programming language.

Surely, this humble starting-point program should be bug free, right?

After all, hello world programs only do one thing. How could there be a bug?

Hello world in C
There are a lot of different ways to write hello world in C. There’s the Wikipedia version, the hello world in the K&R book, and there’s even the oldest known C hello world program from 1974.

This is the most careful version of the bunch. It uses (void) to ensure that main is a new-style declaration. It uses the EXIT_SUCCESS macro instead of just assuming that the platform uses 0 to indicate success, which isn’t necessary, according to the C standard, but we’re not taking any chances here. And it uses the appropriate headers to avoid implicitly declaring puts. This version attempts to do everything right.

And yet, it still has a bug.

All the versions linked above have a bug.