From: Pedro Alves <palves@redhat.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: Joel Brobecker <brobecker@adacore.com>,
gdb-patches@sourceware.org, Matt Rice <ratmice@gmail.com>
Subject: Re: [doc patch] coding style: 0 vs. NULL + [patch] Code cleanup: skip.c
Date: Tue, 11 Dec 2012 10:22:00 -0000 [thread overview]
Message-ID: <50C7093F.5000600@redhat.com> (raw)
In-Reply-To: <20121211060641.GA7775@host2.jankratochvil.net>
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
next prev parent reply other threads:[~2012-12-11 10:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-10 18:42 Jan Kratochvil
2012-12-11 1:54 ` Joel Brobecker
2012-12-11 6:07 ` Jan Kratochvil
2012-12-11 6:51 ` Jan Kratochvil
2012-12-11 10:22 ` Pedro Alves [this message]
2012-12-11 12:01 ` Joel Brobecker
2012-12-11 20:22 ` [doc patchv2] " Jan Kratochvil
2012-12-11 20:39 ` Eli Zaretskii
2012-12-11 20:43 ` Jan Kratochvil
2012-12-12 4:29 ` Joel Brobecker
2012-12-16 19:00 ` [commit] " Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50C7093F.5000600@redhat.com \
--to=palves@redhat.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=ratmice@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox