[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: dynamic_cast performance overhead
From:       David Faure <faure () kde ! org>
Date:       2005-06-02 20:39:44
Message-ID: 200506022239.44722.faure () kde ! org
[Download RAW message or body]

On Thursday 02 June 2005 22:26, Michael Buesch wrote:
> Quoting Michael Buesch <mbuesch@freenet.de>:
> > Maybe a template function or something similiar would be better.
> 
> Such as this. This is tested and prints a friendly debug
> message in DEBUG mode. Otherwise is optimized by the
> compiler to nothing (normal reinterpret_cast).
> I checked the asm output and it looks quite nice to me.
> I consider to use this (or something similiar) in PwManager.
> Detects programming errors in DEBUG mode and is fast otherwise.
But it relies on the developer testing all code paths in the program.

I think this is a bit dangerous. If someone isn't sure whether a dynamic_cast
is needed, and uses this cast "in order to check that", he might conclude the 
wrong thing: if he doesn't hit the "cast failed" error, he might think that the
cast is always ok, and leave things as is, i.e. for the end user an unchecked cast.
And then the end user does something a bit differently - and gets a crash.

IMHO it's better to simply know, as a developer, whether a cast needs to
be checked or not; instead of relying on empirical experience (some testing)
to tell you.

> 	to = reinterpret_cast<ToType>(from);
Should be simply static_cast.

-- 
David Faure, faure@kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic