Pointer if test for for NULL
Chris Johns
chrisj at rtems.org
Thu Apr 29 01:39:30 UTC 2010
Hello,
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.
Chris
[0]
https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=13687
[1]
http://groups.google.com/group/comp.lang.c/browse_thread/thread/0977fba3ad06cd27/059969c527e8bc04
More information about the users
mailing list