Subject: Re: NULL return value checking
To: Matthew Mondor <mmondor@gobot.ca>
From: Alfred Perlstein <bright@mu.org>
List: tech-kern
Date: 04/23/2002 19:57:44
* Matthew Mondor <mmondor@gobot.ca> [020423 19:25] wrote:
> 
> char **foo;
> 
> This would originally have been in my case:
> 
> if(! (foo = malloc(sizeof(*foo))) )
>     fatal("virtual memory exhausted");
> 
> which would become, following /usr/share/misc/style:
> 
> if( (foo = malloc(sizeof(*foo))) ==NULL)
>     fatal("virtual memory exhausted");

Wrong, it would become:

	if ((foo = malloc(sizeof(*foo))) == NULL)
		fatal("virtual memory exhausted");

> and
> 
> if( row[0] && row[1] && row[2] && row[3] ) {
> }
> 
> becoming
> 
> if( row[0]!=NULL && row[1]!=NULL && row[2]!=NULL && row[3]!=NULL ) {
> }

No,

	if (row[0] != NULL && row[1] != NULL && row[2] != NULL &&
	    row[3] != NULL) {
	}

> 
> or
> 
> if(
>     row[0] != NULL
>     && row[1] != NULL
>     && row[2] != NULL
>     && row[3] != NULL
> ) {
> }
> 
> In this particular later case the first form would be more readable
> and is much less typing

Probably, but not when mixed in with other code that follows the
traditional style.  Please stop wasting time trying to convince
people to change a style that's been in use for longer than most
people have been coding.

-- 
-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/