Subject: Re: NULL return value checking
To: NetBSD Kernel Technical Discussion List <tech-kern@NetBSD.ORG>
From: Greg A. Woods@planix.com Greg A. Woods; Planix, Inc. <woods@weird.com>
List: tech-kern
Date: 04/23/2002 17:00:51
[ On Tuesday, April 23, 2002 at 13:20:05 (-0700), Alfred Perlstein wrote: ]
> Subject: Re: NULL return value checking
>
> * Matthew Mondor <mmondor@gobot.ca> [020423 13:14] wrote:
> > Is there real relevance to checking NULL return values against NULL itself, rather than simply using a boolean operation check?
> > 
> > eg:
> > 
> > if( (ptr = malloc(size)) !=NULL) {
> > 
> > instead of
> > 
> > if( (ptr = malloc(size)) ) {
> > 
> > Because isn't NULL defined in <sys/types.h>, to 0L ?
> 
> It's a stylistic choice.  Pointers are not boolean therefor you test
> them against a value in order to derive a boolean for your test.

But since there's no such thing as a true boolean type in C.....

(Personally I really don't like seeing "== NULL" all over the place, and
the opposite -- i.e. "!= NULL" is only slightly less annoying....)

-- 
								Greg A. Woods

+1 416 218-0098;  <gwoods@acm.org>;  <g.a.woods@ieee.org>;  <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>