Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing RTTI flags in C++

Tags:

c++

rtti

If I have multiple linked C++ statically linked libraries in C++, is it possible for them to share (pass to and from functions) class objects if they have been compiled with differing values of enabled/disabled run time type information (RTTI)?

--edit: Thanks for the responses, the specific things I was worried about was 1. Does enabling RTTI change the behaviour of sizeof for static (non polymorphic types)?

and, 2. If I create a class in an RTTI enabled library and pass it to another non RTTI enabled library, do virtual methods work properly. (and vice versa)

and lastly 3. If I create a class in an RTTI enabled library, I expect to be able to use dynamic_cast with it, if I pass that object to a non-RTTI enabled library, can I still use it on that object. ... I would assume not, and it seems like a bad idea anyway... I'm just curious.

like image 294
Akusete Avatar asked Sep 29 '09 04:09

Akusete


1 Answers

How RTTI information is stored is an implementation detail and thus not portable across different compilers.

Also most compilers do not even guarantee that objects compiled with different flags will use the same ABI for their methods. This is most prominently shown with release and debug libraries but other flags can cause differences as well.

Not only may the ABI for functions/methods change but flags can affect the padding used by the compiler between elements in structures thus even objects without virtual methods may be incompatible when compiled with different flags.

When using most IDS you can see the effects. Debug/Release binaries are built into separate directories and only linked against the same kind of binary (also any user defined build will be built into a separate unique directory as a difference in flags may cause incompatibilities). If you change certain flags on a build then the whole project is usually forced to re-build.

like image 137
Martin York Avatar answered Oct 13 '22 12:10

Martin York