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

Jan Kratochvil jan.kratochvil@redhat.com
Tue Dec 11 06:07:00 GMT 2012


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.

>From my point of view:
OK         if (first)
not great  if (!first)
OK         if (first == NULL)
OK         if (first != NULL)
BAD        if (first == 0)
BAD        if (first != 0)

There can be probably just disagreements about the first two cases, whether
they should be forbidden or not, I do not mind.


Thanks,
Jan



More information about the Gdb-patches mailing list