Re: Turn off checks in dynamic_cast of reference types in release builds

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Erik <esigra@xxxxxxxxx> writes:

> Bjarne Stroustrup wrote in his book The C++ programming language that;
> while a dynamic_cast to a pointer type is a question (the result should
> be checked), a dynamic_cast to a reference type is like an assertion. We
> have followed this advice in our project. Now we need to disable these
> assertions in release builds, so that dynamic_cast<Derived &>(base) is
> just as efficient as static_cast<Derived &>(base). But I do not know how
> to tell this to the compiler. I only found some other checks in gcc,
> that can be disabled for release builds, such as the Ada checks (-gnatp).

-Ddynamic_cast=static_cast ?

I don't think there is any other way.  While dynamic_cast to a
reference type is "like" an assertion, it is not in fact an assertion.
The compiler does not provide a way to disable it.


> Or is the feature that I need missing in gcc? Maybe I have to use one of
> the many hacks called down_cast, safe_cast and so on, that can be found
> on the web? Like this one:
> http://smolsky.net/index.php/2009/09/14/down_cast-v2
> If so, which of those hacks is the correct one that should be used?

Since you don't care about dynamic type safety you can just use
static_cast.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux