[Xcb] [PATCH xpyb 01/10] conn.c: Delete explicit comparison with NULL

Christian Linhart chris at DemoRecorder.com
Mon Oct 13 01:17:51 PDT 2014


On 10/13/14 07:53, Alan Coopersmith wrote:
> On 10/12/14 09:47 PM, Tapasweni Pathak wrote:
>> if (pointer == NULL) is functionally equivalent to
>> if (!pointer).
>>
>> Using the second will make it a bit obvious that there is a
>> pointer involved and not an integer or something.
> 
> Really?  I find pointer == NULL to be obviously a pointer, and !value to
> suggest a boolean.   Neither form suggests an integer or other type.
> 
Yes, NULL is definitely a pointer. It is usually defined as ((void*)0).

Therefore using comparison with NULL is more explicit and a clear hint to a pointer.

Using "!value" and "if ( value )" is a rather implicit abbreviation.
(which is rather commonly used, so could be considered a valid idiom, 
and therefore feels more pointer-ish to some people,
depending on what type of code they usually work with.)

***

In essence it boils down to the topic "explicit vs short".

I usually prefer explicit over short because:
with explicit the compiler is more likely to generate errors if something is used the wrong way.
( I learned that by experience. In C it is not so much of an issue. 
But in C++ there is a real danger to shoot yourself in the foot by making too much implicit stuff,
such as defining operator bool for class... But that's another story. )

So my personal opinion is not to merge those changes which remove the NULLs, i.e. patches 1-9.
But I won't object if a majority votes for removing the NULLs.

Chris





More information about the Xcb mailing list