help-gplusplus
[Top][All Lists]
Advanced

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

Re: How disable compiler dynamic_cast optimization?


From: Simon Buchan
Subject: Re: How disable compiler dynamic_cast optimization?
Date: Fri, 23 Sep 2005 22:29:27 +1200
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

Chris Shearer Cooper wrote:
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
You could try going through a void*?





reply via email to

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