Everything You Always Wanted to Know About “Hello, World”
bsdcan.org
bsdcan.org
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);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...
In particular, I am not too happy with the title ;).