Cross compiler exception handling - Can it be done safely?
I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes).
I have already eliminated any use of the STL in the interface.
I have insured that heap corruption will not occur from mixing different new/delete’s.
The final item is exceptions. Can I throw an exception and expect it to be caught correctly by a different version of the com开发者_高级运维piler?
Even considering your additional comment: This will fail whenever MS changes either the compiler's ABI or the class layout of the exception class(es) or even with different compiler settings. In fact, the latter might cause failure even with the same compiler.
So I guess the answer is: No you cannot do this safely. If you want to pass non-POD objects between executables, they should be compiled with the same compiler, the same std library, and the same (to some degree) compiler settings.
I would expect that to be up to the compiler vendor, I don't think the standard specifies how exceptions are to be implemented, so it can't guarantee you a consistent implementation.
Most likely not. Each version of the compiler will have its own runtime environment that is completely unaware of the other environment. Unless the vendor states explicitly that this is possible is it most likely not possible.
精彩评论