Mixing C, C++ and exceptions

Uli Kusterer kusterer at gmail.com
Mon Aug 20 03:35:22 PDT 2007


  I tried googling for this info, but my Google-fu seems to be out of  
order today (if anyone wants to share search terms where they found  
anything, I'd be grateful)...

  THE QUESTION: If I'm mixing C and C++ code compiled as separate  
units (i.e. some in .c and some in .cpp files), is it safe for the C+ 
+ code to throw exceptions "through" the C++ code, ABI-wise? Will the  
stack get unrolled OK and all that?

  I'm not talking about problems I might be getting with the C code  
leaking memory or not releasing resources it's acquired before the  
exception happened, I'm aware that this will happen when an exception  
happens before clean-up, but apart from that, does it work? I thought  
I'd heard somewhere it didn't, but couldn't find anything, so I  
thought I'd ask here if anyone has better memory than I do.

  And while we're at it, can anyone confirm/deny that the same does  
NOT apply to Objective C exceptions? Since they use longjmp under the  
hood, they won't unroll the stack correctly, right?

Cheers,
-- M. Uli Kusterer
http://www.zathras.de





More information about the MacOSX-dev mailing list