[vbox-dev] [PATCH 2/8] Fix an implicit conversion from pointer to bool

Jung-uk Kim jkim at FreeBSD.org
Thu Mar 26 19:48:30 UTC 2015

Hash: SHA256

On 03/26/2015 15:25, Michal Necasek wrote:
> Sorry, I wasn't clear. By "what is the semantic difference" I meant
> "under what circumstances will the conditional behave differently".
> There must be some difference because otherwise what would be the
> point of a warning?

As I said, it does not behave differently under any circumstances.  It
just shuts up compiler warnings.  I think the warning is to make sure
its author is using a correct variable, i.e., "A variable of type foo
is used where type bar should be used.  Do you really want me to
convert it to type bar?" or something like that.

Some people say it's too noisy but I didn't write the compiler. :-P

> Remember that programmers can have a hard time reading compilers'
> minds, too.

Last time I checked compilers lacked mind. ;-)

Jung-uk Kim

> ----- Original Message ----- From: jkim at FreeBSD.org To:
> michal.necasek at oracle.com, vbox-dev at virtualbox.org Sent: Thursday,
> March 26, 2015 7:59:29 PM GMT +01:00 Amsterdam / Berlin / Bern /
> Rome / Stockholm / Vienna Subject: Re: [vbox-dev] [PATCH 2/8] Fix
> an implicit conversion from pointer to bool
> On 03/26/2015 14:03, Michal Necasek wrote:
>> The question isn't whether a compiler can warn. The question is, 
>> why should it?
> Although this specific code has absolutely no problem, compilers
> are not smart enough to read authors' mind yet. ;-)
>> What you quoted doesn't contradict what Frank said. There is a
>> very well defined pointer to bool conversion. So what's the
>> problem? Or in other words, what is the semantic difference
>> between
> The difference is
>> if (ptr)
> ptr is converted to bool type first
>> and
>> if (ptr != NULL)
> ptr is compared to nullptr (if NULL is correctly defined as
> nullptr).
> Basically, the first is a conversion and the second is a
> comparison.
> Jung-uk Kim
Version: GnuPG v2


More information about the vbox-dev mailing list