This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [doc patch] coding style: 0 vs. NULL + [patch] Code cleanup: skip.c


On 12/11/2012 06:06 AM, Jan Kratochvil wrote:
> On Tue, 11 Dec 2012 02:53:43 +0100, Joel Brobecker wrote:
>>> But GDB (IMO fortunately) already uses everywhere properly NULL vs. 0.
>> [...]
>>> I have added a new rule for the coding style for it.
>>
>> So, just to be certain, this also includes testing for NULL, right?
> 
> I did not think about this case.
> 
> 
>> Code like...
>>
>>         first = strstr (big, small);
>>         if (first)
>>
>> ... should be written instead:
>>
>>         if (first != NULL)
> 
> I find '(first)' OK myself but IIRC Pedro recently in some mail wrote he likes
> more an explicit NULL comparison there.  Although I cannot find his mail now
> so I hope I do not put these words in Pedro's mouth.

Yes, indeed I mentioned it recently somewhere.  Personally, I find
implicit boolean conversions make the code harder to grok, so I prefer the
latter.

> not great  if (!first)

Indeed.  That's about the same level of badness as '!strcmp(a, b)' to me.

> OK         if (first)

I look at this the same as '(!first)' - it's the same implicit boolean conversion,
so I look at it as a matter of consistency to write 'if (first == NULL)' if one
writes 'if (first != NULL)'.

-- 
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]