Felix Kater wrote:
Hi,
if I want to make sure that neither the pointer arg nor the value to
which it points to is NULL: Is solution (a) safe -- or does it have to
be like (b) ?
NULL is a null pointer constant. It might be a literal 0 on your
implementation, but this is not true on several others. If you're
comparing *p to NULL because p is a pointer to a pointer to something,
you should declare p as such. If you're comparing *p to NULL because
you want to know if it is zero, just check for 0. That said, the && and
|| operators don't evaluate their right operands if the result is known
from the left, so both ways are just as safe.
Felix
void f(int* p){
/* (a) */
if(p==NULL || *p==NULL) return;
/* (b) */
if(p==NULL) return;
if(*p==NULL) return;
}