M
matevzb
Well yes, if you want to abort() I suppose that's okay.So there's a memory leak for some tiny number of clock cycles until abort()
is called... big deal.
Personal opinion: I'd rather not do it in a macro, especially one with"E.g." means "for example". As you admit, this example already has uses -
in many small single-purpose programs it simply doesn't make sense to
carry on if you can't allocate memory.
With a little initiative you can modify the macro... e.g. have a global variable
to store the original pointer, and replace abort() by some cleanup
code.
the same name as a C library function - it's obfuscation.
Another personal opinion: The "few occasions" may not be so few whenIf you do it right, you'll be able to transparently handle allocation
failures in-place too, on the few occasions when that's really beneficial.
dealing with e.g. large databases or daemons.
It's quite easy to be consistent when writing code all by yourself. IfThat's personal opinion. Consistency and clear documentation are what
make code easier to debug. I personally find source files with hundreds
of if-clauses for (m|re)alloc failure scattered everywhere far harder
to read.
not, I'd rather take every precaution necessary, rather than rely on
consistency and clear documentation. People are sometimes forgetful,
sloppy, unaware or just plain lazy, so I rely on the code instead.
This is also a personal opinion, derived from experience.