|
|
|
|
|
by loxias
3037 days ago
|
|
Oh, I'm not saying you should test for NULL and then, uh, not care about the result! If you port to some new platform, of course you need to go back and check the docs for new error codes. For instance, I generally abort() on NULL after printing a message. |
|
Ok, but...how are you printing the message?
On many platforms, with many standard libraries (glibc, for instance), printf et al will themselves malloc memory, so you're testing for a system telling you it couldn't allocate memory and then in response, potentially triggering further quite-likely-failing allocations that may or may not be handled by the library.
This is why people generally don't bother to check for NULL mallocs. Even if you're on a system that will even tell you you're in that situation (rare, these days, outside of the embedded world), there's almost nothing useful you can do.