3 ms·
I typically don't check the return code of `printf`, but for the same reason you state: I've looked at its failure modes, and decided that awareness of the fail
by DoofusOfDeath 7y ago
I typically don't check the return code of `printf`, but for the same reason you state: I've looked at its failure modes, and decided that awareness of the failure wouldn't impact my desired flow of the code.
I rarely use `malloc`, but I typically do check its return code. That's because in my experience, hunting down the root cause of segfaults can be a hassle, so I prefer to write code that will fail fast on failed memory allocations.
- MaulingMonkey 7y agoFor most programmers starting out, I imagine they didn't even realize printf could fail. I certainly didn't initially. > That's because in my experience, hunting down the root cause of segfaults can be a hassle, so I prefer to write code that will fail fast on failed memory allocations. This is a great reason to add error checking. I've spent enough time hunting down harder dangling pointers and memory corruption bugs that alloc-returned-nullptr segfaults are trivial/second nature for me to figure out 99% of the time. There is that remaining 1% of cases, for the already rare scenario where malloc has failed. Quite niche... but sometimes motivation enough for me to go through with adding error checking anyways. Especially if I actually encounter it.