0 or 0L for empty pointers?
André Wöbbeking
Woebbeking at onlinehome.de
Fri Jun 23 16:20:06 BST 2006
On Friday 23 June 2006 16:32, Allan Sandfeld Jensen wrote:
> On Friday 23 June 2006 14:03, Stefan Teleman wrote:
> > I think dynamic_cast<> is your friend. It comes with failure
> > guarantee which returns NULL for pointers (a Good Thing(TM)). It
> > throws for references but then i've rarely seen it used on
> > references anyway.
>
> It is _not_ your friend, since you can't trust it. See the other
> replies.
>
> Even with ways to make it work. It's kinda cryptic and just shouldn't
> be trusted. If you need failure safe type-casting, do your own
> type-system/use Qt's and use static_cast<> (personally I prefer
> C-casts, but I guess I'm just oldfashioned).
Don't use C-casts. They cast to everything without checking the type.
> Also while it doesn't cost you very much to use dynamic_cast<>; if
> you don't use it at all, you can disable C++ RTTI and save a lot of
> memory and speed.
Any numbers on this especially with recent compilers?
Cheers,
André
More information about the kde-core-devel
mailing list