[bind10-dev] suggested team call agenda
JINMEI Tatuya / 神明達哉
jinmei at isc.org
Tue Jan 15 04:17:24 UTC 2013
At Wed, 12 Dec 2012 08:30:57 +0000,
Francis Dupont <fdupont at isc.org> wrote:
> > Yeah, in this discussion, we should at least distinguish the direct
> > use of pointer value as boolean like
> >
> > Foo* foo;
> > if (foo) {
> > ...
> > }
>
> => IMHO this is bad style because foo is in no way a boolean.
On reading the language spec again, I realized I overlooked one thing.
Pointers can be converted to boolean per the standard conversion
rules:
"An rvalue of arithmetic, enumeration, pointer, or pointer to member
type can be converted to an rvalue of type bool. A zero value, null
pointer value, or null member pointer value is converted to false;
any other value is converted to true."
So, except that it relies on implicit conversion, this is actually
type safe in C++. Relying on implicit *something* is itself
controversial in general, but that equally applies to relying on the
type conversion operator for shared_ptr. To this end I now don't see
a reason for ban this style for bare pointers if we accept it for
shared_ptr at least in terms of type safety.
Remaining issue to me is the fact of relying on the implicit
conversions and consistency with the BIND 9 style
(http://bind10.isc.org/wiki/BIND9CodingGuidelines "Null Pointer").
As for the former, I'd generally be careful about relying on implicit
conversions simply for some seeming convenience. But this semantics
for pointers/pointer-like-types is quite common, so I'm personally
okay with using it in this case.
As for the latter, I'm basically neutral, but slightly inclined to
break the consistency, considering the balance between advantages and
drawbacks.
---
JINMEI, Tatuya
More information about the bind10-dev
mailing list