3 ms·
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
by dietrichepp 10y ago
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 10y agowrite(1, hello, sizeof(hello)-1);