[bind10-dev] suggested team call agenda
Francis Dupont
fdupont at isc.org
Tue Jan 15 08:46:01 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
=> I have two comments about this issue which can be summarized by the
same "C++ is not C":
- in C there is not implicit or explicit conversion to boolean,
nor in fact a boolean type, so the only correct choice is to
compare pointers with NULL.
- in C++ there is no NULL: it is imported from C for compatibility
but formally pointers should be compared with (or assigned to) 0
or in last C++ specs nullptr.
Because of the second item now I believe to ban implicit conversion in
this case has no a positive pros vs cons.
Regards
Francis Dupont <fdupont at isc.org>
More information about the bind10-dev
mailing list