This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [doc patch] coding style: 0 vs. NULL + [patch] Code cleanup: skip.c
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: gdb-patches at sourceware dot org, Matt Rice <ratmice at gmail dot com>, Pedro Alves <palves at redhat dot com>
- Date: Tue, 11 Dec 2012 07:06:41 +0100
- Subject: Re: [doc patch] coding style: 0 vs. NULL + [patch] Code cleanup: skip.c
- References: <20121210184220.GA29321@host2.jankratochvil.net> <20121211015343.GM31477@adacore.com>
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