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: Mon, 26 Sep 2005 19:21:21 +1200
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

Chris Shearer Cooper wrote:
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 ...
How about:
A* ap = ...;
void* vp = reinterpret_cast<void*>(ap);
D* dp = dynamic_cast<A*>(reinterpret_cast<A*>(vp));

If the compiler optimises that away, I'm not only impressed, I'm confused as to why it would. Consider whether there is a simpler way to do what you /really/ want to do. (If you are doing stuff like this, there almost always is.)





reply via email to

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