Skip site navigation (1) Skip section navigation (2)

Re: sparse (static analyzer) report

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Greg Stark <gsstark(at)mit(dot)edu>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: sparse (static analyzer) report
Date: 2005-01-15 13:31:42
Message-ID: 41E91B3E.3050508@dunslane.net (view raw or flat)
Thread:
Lists: pgsql-hackers

Tom Lane wrote:

>Greg Stark <gsstark(at)mit(dot)edu> writes:
>  
>
>>Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> writes:
>>    
>>
>>>Hmm.  Well, it showed the multiple incorrect uses of 0 as NULL in
>>>dllist.c and other places, 
>>>      
>>>
>
>  
>
>>Incidentally, while it may not be conformant to your style guidelines, use of
>>the constant 0 compared to or assigned to a pointer is a perfectly valid ANSI
>>spelling for NULL.
>>    
>>
>
>Absolutely.  But I agree that it is more readable to use NULL when you
>mean a null pointer, and 0 when you mean an integer zero.  The C
>standard may not distinguish these concepts, but I do ;-)
>
>Something that I don't have a real strong feeling about is
>	if (ptr != NULL)
>versus
>	if (ptr)
>I've been known to write both.  Can anyone mount a good readability
>argument for one over the other?
>
>How about the inverse case,
>	if (ptr == NULL)
>versus
>	if (!ptr)
>Applying a boolean ! to a pointer seems a bit shaky to me, though
>it's certainly a common locution.
>
>
>  
>

If we allow "if (ptr)" then allowing the inverse to be "if (! ptr)" 
seems logical enough. As you say, it's a very common idiom, and allowing 
one without the other would be rather non-orthogonal.

cheers

andrew

In response to

Responses

pgsql-hackers by date

Next:From: Alvaro HerreraDate: 2005-01-15 13:41:37
Subject: Re: sparse (static analyzer) report
Previous:From: Peter EisentrautDate: 2005-01-15 08:33:51
Subject: Re: [PORTS] 8.0.0rc4 / OpenBSD 3.6 / amd64 success

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group