This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Turning off C++ casting?
Paolo Bonzini <paolo dot bonzini at polimi dot it> writes:
| On Thursday 20 February 2003 13:17, Gabriel Dos Reis wrote:
| > Paolo Bonzini <paolo dot bonzini at polimi dot it> writes:
| > | The point was to avoid the performance impact (assuming there is) of
| > | dynamic_cast in non-debugging releases.
| >
| > If you know for sure that the derivation actually holds, then use
| > static_cast<>, -not- reinterpret_cast<>.
|
| You do because of the assert.
That is funny because you previously stated that you wanted to avoid
the dyanmic_cast<>. Now, you're telling me that you are going to do it
anyway. That is an *inconsistent* position.
| So the correct answer to the poster's question
| is to use
|
| assert (dynamic_cast<ExtendedObject*>(&baseObj) != NULL);
| ExtendedObject& obj = *static_cast<ExtendedObject*>(&baseObj);
If you're going to do the dynamic_cast<>, then reuse the result:
ExtendedObject* ptr = dynamic_cast<ExtendedObject*>(&baseObj);
assert (ptr != 0);
// use ptr
All this has nothing to do with GCC.
-- Gaby