views:

99

answers:

3

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 compiler?

+1  A: 

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.

unwind
+1  A: 

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.

jmucchiello
+8  A: 

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.

sbi
GCC used to intentionally generate code that would not link to other compilers specifically because of issues like this. With the de facto standardized ABI an most non-Windows platforms, they've stopped doing that, though.
Max Lybbert