[osg-submissions] Misc compile fixes on different *nix variants.
Mathias Fröhlich
M.Froehlich at science-computing.de
Fri Jun 27 05:39:42 PDT 2008
Robert,
On Friday 27 June 2008 14:06, Robert Osfield wrote:
> To fix the NodeVisitor warnings I have changed the implementation so
> the header doesn't do the apply((Goup&)node); etc. calls, instead
> moving these to the NodeVisitor.cpp and use static_cast<> instead.
>
> As this change is pretty safe I've gone ahead and check it into SVN.
I do not think that this is safe.
I will try it out if you wish, but the warning tells you that the compiler
does not know the class layout of these classes in question. So the compiler
does not know if this cast will add an offset to the pointers in question.
Since this is not known the compiler just assumes that there is a zero offset
between those pointers which means it will use a reinterpret_cast for that
cast. To make that work in general the declarations of these classes need to
be present. If you do a static_cast here, the compiler enforces that these
declarations are present - there is no other chance for the compiler since
static_casts might add an offset to a pointer and this is guaranteed to work
correct, which cannot because of the decl missing .....
If not you will get an error instead of this warning. Sure as often, gcc
accepts that. But some others don't which is more standard conforming.
If you change that you have to either:
- include the class declarations of all these classes and do a static cast or
that c style cast which is then compiled like a static_cast, or
- replace the c cast with a reinterpret cast with all the pitfalls comming
with that.
I expect that the reinterpret_cast method works since the classes in question
already have a class layout on all those compilers/architectures I know of,
so that a pointer to those classes does not get an offset by that casts.
You might now ask when such an offset is required. That is compiler and abi
dependent. But for you favourite abi this will happen when you have multiple
inheritance or if a base class has no vtable but an inheritted one introduces
a vtable for example. There might be more situations where this happens ...
It would be good when this warning is gone...
Thanks and Greetings
Mathias
--
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511
--
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Florian Geyer,
Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Prof. Dr. Hanns Ruder
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196
More information about the osg-submissions
mailing list