Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Everything You Always Wanted to Know About “Hello, World” (bsdcan.org)
56 points by signa11 on July 2, 2016 | hide | past | favorite | 9 comments


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");


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


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


A link that focuses on higher level issues regarding I/O streams in C: https://www.irill.org/videos/GNU_Hackers_Meeting/jim-meyerin....

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


Could someone add [video] to the title?


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.


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.


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.


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: