help-gplusplus
[Top][All Lists]
Advanced

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

How disable compiler dynamic_cast optimization?


From: Chris Shearer Cooper
Subject: How disable compiler dynamic_cast optimization?
Date: Thu, 22 Sep 2005 15:26:37 -0600

Using gcc version 3.2 ...

The compiler likes to optimize away calls to dynamic_cast - so, for 
instance, if I do this :
class Base { ... }
class Derived : public Base { ... }
Base b;
Derived *d = dynamic_cast<Derived*>((Derived*)&b);
(yes, that's a stupid thing to do, it's just that to explain the real issue 
would take more pages than you want to read)
That code happily sets d to &b because the compiler says "Hum, I've been 
given a Derived*, obviously that's the same as a Derived*, so I can just 
turn the dynamic_cast into a static_cast."

Is there a way to disable this particular optimization?

Thanks!
Chris




reply via email to

[Prev in Thread] Current Thread [Next in Thread]