
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.