Subject: Re: NULL return value checking
To: NetBSD Kernel Technical Discussion List <tech-kern@NetBSD.ORG>
From: Alfred Perlstein <bright@mu.org>
List: tech-kern
Date: 04/23/2002 14:31:48
* Greg A. Woods@planix.com Greg A. Woods; Planix, Inc. <woods@weird.com> [020423 14:02] wrote:
> [ 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.....

You're missing the point.

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

Your personal opinion doesn't matter.

-- 
-Alfred Perlstein [alfred@freebsd.org]
'Instead of asking why a piece of software is using "1970s technology,"
 start asking why software is ignoring 30 years of accumulated wisdom.'
Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/