Turning off C++ casting??
Jack Lloyd
lloyd@acm.jhu.edu
Wed Feb 19 23:37:00 GMT 2003
In the case of dynamic_cast, this would be a tremendously bad idea. The
reason dynamic_cast is so useful is because it allows you to do a cast even
when you're not sure that the cast is correct; the dynamic_cast will test
it for you. Replacing dynamic_cast with a static cast would cause all sorts
of messes, given most uses of dynamic_cast. The other cast operations are
just as cheap as a C-style cast, so it's a non-issue.
-Jack
On 19 Feb 2003, Mongryong wrote:
> Is there a way to disable C++ casting? That is, during
> development/debugging I like using C++ casts like dynamic_cast to ensure
> my parameters are correct. However, for a release build where I'm
> confident 'all down-casting' is safe, I would like the casting to be
> turn off - that is, something similar to 'C' type casting:
>
> // Debug build
> void func(BaseObject& obj) {
> ExtendedObject& obj = dynamic_cast<ExtendObject&>(obj);
> //...
> }
>
> // Release build
> void func(BaseObject& obj) {
> ExtendedObject& obj = *((ExtendObject*)((void*)arg)); // release build
> //...
> }
>
> Correct me if I'm wrong, but I believe the release build is faster.
>
>
>
More information about the Gcc
mailing list