1) Should a function check each of it's pointer arguments for NULL?
void do_stuff(char** object1, char** object2, ...) {
if (object1 == NULL) {
return;
}
if (object2 == NULL) {
return;
}
...
2) When a function creates a dynamic object, should it return a pointer to a newly created abject or should it assign it to it's argument?
void allocate_object(char** object);
or
char** allocate_object(void);
3) When a function is intended to allocate an object and fails to do so, how to notify the caller about the result?
return -1;
or
object = NULL;
4) Who (in general) is responsible (check, free) for a pointer argument: a function or it's caller?
5) Are there any guidelines or resources that answer similar questions?
With C++ and it's classes, each object has it's owner. This, together with RAII and exception handling helps me to answer my questions. In C, I am yet to understand this.