Pointer if test for for NULL

Chris Johns chrisj at rtems.org
Thu Apr 29 01:39:30 UTC 2010


The Austin Group (Open Group) has been having a discussion about NULL 
meaning all bits 0 [0][1]. For example:

  struct s* p;
  p = malloc (sizeof (struct s));
  if (p)
    memset (p, 0, sizeof (*p));

The issue raised is "If 'struct s' contains a pointer is the pointer 
initialised to NULL correctly ?". This is not what I wish to discuss.

Considering this I am wondering if the 'if (p)' code is strictly valid ?

Does this code also imply false happens if NULL is all bits 0 ?

Should this code be changed to:

  if (p != NULL)

I am guilty of coding the if's this way and I am wondering if this 
should be changed.



More information about the users mailing list