[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 GMT 2015


-----BEGIN PGP SIGNED MESSAGE-----
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJVFGKJAAoJEHyflib82/FGBSUH/2B+WuYaX4Ov8AOYz4F4ogvK
HGUb9QJ0cKntIlQZSk4FTa0B0Bu7p3wjoC/UE7CIySd1tfKbU7/wBvTvTeMgNYop
JCNwkbjJVr2KV/DurdrC8lbt2jClZl6JpMrIpkmTbjMCggDEl10b/3+wvF1P+9Vv
j58UWAA0u5eMRgDvY6TotIP/ZKlFB19OmGJpAtZQH0kJA8FB6CwaaoQ1v+EMw4Ek
ZGrfinHY6+ujd5oxEdS03uE5vl+6oURGfTT9hdr1WeHxR9JftZDGraa0LQWMRV8K
kBMR+b4h70shYEjqA264raavK6bcoiUl63l1LA3vkeyJUZmrCDHd5UwdoQZwrkE=
=sgAo
-----END PGP SIGNATURE-----




More information about the vbox-dev mailing list