[Scummvm-devel] Porting headaches
Jamieson Christian
jamiesonc at tds.net
Mon Dec 8 15:32:01 CET 2003
----- Original Message -----
From: "Arisme" <arisme at free.fr>
Sent: Monday, December 08, 2003 4:56 PM
I'm having some troubles with one very tiny part of the code, in dialogs.cpp
where misc functions from GUI::OptionsDialog are called from
Scumm::OptionsDialog
-------------------------------------------------------
This is also a problem in MSVC6. The PocketMatrix post recommending
reinterpret_cast<>, however, does not sound like the best solution.
reinterpret_cast is the most dangerous casting operator to use because it
simply reinterprets your pointer as being of a different type, without any
appropriate transformations. My understanding of vtables (which is limited)
is that interpreting a derived class pointer as a base class pointer will
actually mean a pointer with a slightly different value, to point to a new
vtable at the very least.
Since GUI::OptionsDialog is a base class of Scumm::OptionsDialog, you should
simply be able to do a conventional typecast:
((GUI::OptionsDialog*)this)->open();
This at least compiled on MSVC6 (changing, also, the ::close() and
::handleCommand() calls). If I can ever get the damn thing to finish
compiling and linking everything else (damn BS2 code!), I can see if it
works in runtime.
If the above does not work, a static_cast<> is still preferable to a
reinterpret_cast<>. Fingolfin would be able to provide more details on this.
I think he probably wrote the original code anyway?
(Well, just finished trying to link once again, and a whole bunch of other
crap is broken as well, so I won't be able to test run-time behavior just
now. Sorry.)
-- Jamieson (sf.net: Jamieson630)
More information about the Scummvm-devel
mailing list