Boost logo

Boost :

Subject: Re: [boost] Old style casts and Boost style guidelines
From: Edward Diener (eldiener_at_[hidden])
Date: 2008-09-15 21:47:24


Peter Dimov wrote:
> Edward Diener:
>> Peter Dimov wrote:
> ...
>>> (Y*)0 is so much nicer than static_cast< Y* >( 0 )... :-/
>>
>> It is shorter, as are most uses of old-style casts as opposed to C++
>> new-style casts, but what makes it "nicer" ?
>
> It's easier to read. C-style casts, in general, are shorter, but not
> necessarily easier to read, because one needs to look up the source (and
> sometimes target) types to determine what the cast actually does (is it
> a static_cast, a reinterpret_cast, a const_cast, or a combination) and
> whether it's correct. This slows the reader down, which is not nice.
>
> In this case, though, the meaning is unambiguous. (Y*)0 is - obviously -
> a null pointer "literal" of type Y*. So it's nice. :-)

If 'nullptr' becomes part of C++ in the future I imagine that one would
be able to implicitly pass that around without casting at all whenever a
pointer is appropriate. This would eliminate such a consideration in the
present case.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk