
16 Sep
2008
16 Sep
'08
12:52 a.m.
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. :-)