开发者

C++ Separate Compilers for classes (vtables)?

I was wondering what the consequences are for compiling a class A with one compiler that doesn't allow multiple inheritance, and compiling a class B that does support it (and class B derived from class A).

I don't really und开发者_运维知识库erstand the linking process...would it be possible to use both together? What disadvantages exist for using separate compilers in this situation, with vtables? Would it be impossible for code using class B to function properly?

Thanks.


As a general rule, don't ever compile parts of your C++ program with different compilers.

Different compilers may use, and often do, different mangling schemas for the symbol mangling stage, so it's very unlikely that the linking between separately compiled stuff will work.

See doc about mangling name_mangling


Object layout (vtable pointer location, vtable format, sub-object placement, etc.) is not guaranteed to be the same between the compilers.


It's not just classes that won't be able to talk to one another. Bare functions declared in a header but compiled only by one of the compilers will be invisible to the other compiler because of name mangling.

Also, any static classes/members of classes compiled by the compiler that does NOT compile main() will not initialize correctly because that compiler's runtime will not be executed. Even things like 64bit long long arithmetic (on 32bit platforms) might not be linked correctly because of the conflicting runtime libraries.


As an addendum to Arkaitz's post above, you may find other issues that could stop code working together from compilation units built with different compilers:

  1. data size issues (eg one compiler uses 32 bit ints, the other 64 bit)
  2. data alignment issues
  3. issues with heap memory

Basically anywhere that the C++/C standards isn't very specific about things leaves scope for differences between compilers, and hence scope for problems mixing them

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜