Pray tell, how many places is appropriate to call the same function? Is 5 too many? How about 6? When I hit 7, I have to refactor everything, right?
Unless there's an actual performance implication, this is all purely a matter of taste. This is the kind of broadly true, narrowly false stuff that causes people to destroy codebases. "I can't write it this way, because I have to push ifs up and fors down!!!" It's a totally fake requirement, and it imposes a fake constraint on the design.
static inline int function(blob *ptr, int arg)
{
if (ptr == NULL)
return ERR_NULL;
return real_function(ptr, arg);
}
Just like that, we effectively moved the if statement into 37 callers, where the compiler may be smart enough to hoist it out of a for loop when it sees that the pointer is never changed in the loop body, or to eliminate it entirely when it sees that the pointer cannot be null. free(NULL); // convenient no-op, does nothing
fflush(NULL); // flush all streams; done implicitly on normal exit
time(NULL); // don't store time_t into a location, just return it
strtol(text, NULL, 10); // not interested in pointer to first garbage char
setbuf(stream, NULL); // allocate a buffer for stream
realloc(NULL, size); // behave like malloc(size)
and others. More examples in POSIX and other APIs: sigprocmask(SIG_UNBLOCK, these_sigs, NULL); // not interested in previous signal mask
CreateEventA(NULL, FALSE, FALSE, NULL); // no security attributes, no name
Reality just ran over your opinion, oops!