3 ms·
You're joking right? There's zero, zilch, nada need to check the error return from a Hello, World program. Hello World is a standard way to show you can compile
by labrador 4y ago
You're joking right? There's zero, zilch, nada need to check the error return from a Hello, World program. Hello World is a standard way to show you can compile and run a program. If you can't do Hello World, you can't do anything else. It's a good joke though. I'll probably steal it.
- murderfs 4y agoWhen was the last time you've seen someone check the return value of printf?
- yakubin 4y agoAnd what is your program supposed to do when printf fails? Print an error?
- kelnos 4y agoPerhaps "return 1", at least. If writing to the console fails for some reason, when the entire purpose of the program is to write something to the console, the program shouldn't exit with a status of zero. Arguably a "correct" hello world in C is: #include <stdio.h> #include <string.h> #define HI "Hello, world\n" int main() { if (printf(HI) != strlen(HI)) { return 1; } return 0; } (And I'm sure astute readers could even find fault with this implementation.) Obviously this is tongue-in-cheek; I would never write code that checks the output of printf(), even if perhaps, in some abstract way, I "should". If we were to believe that the purpose of a "hello world" program was to teach about error handling, then maybe we should write "hello world" this way. But I'm also not sure that's its purpose.