3 ms·
For 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, hunt
by MaulingMonkey 7y ago
For 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.