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: Chris Shearer Cooper
Subject: Re: How disable compiler dynamic_cast optimization?
Date: Fri, 23 Sep 2005 07:47:22 -0600

I am pretty sure that doesn't work ... it won't dynamic cast from something 
that isn't an object 'cuz if it doesn't optimize it away, it does it using a 
virtual function at run-time ...

"Simon Buchan" <simon@hand-multimedia.co.nz> wrote in message 
news:mailman.8213.1127475229.20277.help-gplusplus@gnu.org...
> 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]