This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Turning off C++ casting?
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: bonzini at gnu dot org
- Cc: gcc at gcc dot gnu dot org, mongryong at sympatico dot ca
- Date: 20 Feb 2003 11:06:31 +0100
- Subject: Re: Turning off C++ casting?
- Organization: Integrable Solutions
- References: <200302200957.32698.paolo.bonzini@polimi.it>
Paolo Bonzini <paolo dot bonzini at polimi dot it> writes:
| s> But if I'm iterating over lots of
| > objects, I'd like to get rid off the cost of dynamic_cast when I know
| > for sure the objects will always be of this type.
|
| assert and the pointer version of dynamic_cast are your friends if you don't
| want #ifdefs.
|
| assert (dynamic_cast<ExtendedObject*>(&baseObj) != NULL);
| ExtendedObject& obj = *reinterpret_cast<ExtendedObject*>(&baseObj);
Please write the last line as
ExtendedObject& obj = *dynamic_cast<ExtendedObject*>(&baseObj);
-- Gaby