On Feb 19, 2008, at 9:45 AM, Stefan Werner wrote: On Feb 18, 2008, at 8:11 PM, Howard Hinnant wrote:
Yes. To propagate a C++ exception through a C stack frame, that C stack frame must be compiled with -fexceptions (which is defaulted off for .c files). From the gcc docs:
However, you may need to enable this option when compiling C code that needs to interoperate properly with exception handlers written in C++.
Thanks, that was it.
I'm still puzzled about GCC_ENABLE_CPP_EXCEPTIONS though. The built-in documentation of it in Xcode is a verbatim copy of what the man page says about -fexceptions. However, GCC_ENABLE_CPP_EXCEPTIONS = YES odes not add -fexceptions. Is that desired behavior?
OK, this is a slightly deceptive artifact of Xcode's build system and build setting UI.
"Enable C++ Exceptions" only appears for targets that include C++ code. Its default state is checked, that is, C++ exceptions are enabled by default; uncheckking it sets -fno-exceptions explicitly.
For C code it's absent, as C normally ignores this.
For mixed C and C++ code, the default item is present, but performs the default action in both languages, that is, leaves exceptions enabled in C++ but ignores them in C. Which is not what you desire, no. The solution is to explicitly check Enable C++ Exceptions at the target level, rather than leaving it enabled by default. That way you get the consistent explicit behavior (-fexceptions) for both C and C++ code, rather than the inconsistent default behavior.
Chris |