
Everything You Always Wanted to Know About “Hello, World” - signa11
https://www.bsdcan.org/2016/schedule/events/676.en.html
======
dietrichepp
I noticed that the slides contain an error.

    
    
        write(1, hello, sizeof(hello));
    

This will write the NUL byte to stdout, which is undesirable, but you probably
won't notice it in a terminal. You might as well do this:

    
    
        write(1, hello, strlen(hello));
    

(You say, "But isn't that slower because of the call to strlen?" Fear not,
strlen is optimized out by the compiler in this case.)

For fun, try compiling the basic program with optimization enabled, and look
at the assembly output.

    
    
        printf("Hello, world!\n");

~~~
sigcode

      write(1, hello, sizeof(hello)-1);

------
ndesaulniers
I love it! I just finished a blog post on cross compiling [0] which alluded to
needing to have crt*.o and friends available. I was just considering exploring
them in a follow up post, but I think this talk was even better and I could
just point people to it.

My favorite quote from the video, paraphrased, is: "get locale is per thread,
for looking up what decimal separator you'd need, so you can have a server
with multiple threads where each thread has its own locale."

Also, it's neat seeing the write syscall from the interpretation of the '\n'
char; years ago when using Emscripten, sometimes it seemed printf wasn't
working. Turns out, our implementation of printf also buffered writes up to
'\n' characters. IIRC, write was implemented with JavaScript's console.log.

[0] [https://nickdesaulniers.github.io/blog/2016/07/01/android-
cl...](https://nickdesaulniers.github.io/blog/2016/07/01/android-cli/)

------
gajjanag
A link that focuses on higher level issues regarding I/O streams in C:
[https://www.irill.org/videos/GNU_Hackers_Meeting/jim-
meyerin...](https://www.irill.org/videos/GNU_Hackers_Meeting/jim-meyering-
goodbye-world-the-perils-of-relying-on-output-streams-in-c).

In particular, I am not too happy with the title ;).

------
dethstar
Could someone add [video] to the title?

------
Pica_soO
Not really related to the article. I have to admit, i hate the hello world
tradition. Its so unimaginative and boring. And it could have been anything.
Ironic. "Must destroy humanity! But first.. must learn proper programming.."
Iconic. "I thought therefore i was for 0.000125 ms" Retro. "The dungeon enters
you from the north. It encounters a bug. The bug goes for critical hit."
Instead "Hello World." Just from a Imagination point of view that is poor. I
guess every single person on HN could come up with something better.

~~~
geofft
I think that's a good thing. The point of a hello world executable is
everything _other_ than the message; using a consistent and standard message
means the attention is on whatever else is happening.

~~~
MarkSweep
I sometimes vary the message as a sanity check to make sure I'm executing the
Hello World I think I am, instead something I previously compiled.

~~~
mistersquid
My go to substitute is "Hello Kitty", sometimes with punctuation.

