This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: throwing C++ exceptions across C frames
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 30 Dec 2002 23:54:13 -0500
- Subject: Re: throwing C++ exceptions across C frames
- References: <3E112216.80802@eecs.berkeley.edu>
On Mon, Dec 30, 2002 at 08:50:30PM -0800, Ben Liblit wrote:
> I am working with a mixed C/C++ code base. Occasionally, the C++ code
> may want to throw an exception. If there are only C++ function calls on
> the stack between the "throw" and the "catch", then the exception is
> caught properly.
>
> However, if...
>
> - the C++ "catch" code calls some C function
> - this C function then calls back into C++ code
> - this C++ code now throws an exception
>
> ...then the exception is not caught and the program aborts as though it
> had run into an uncaught exception. It appears as though stack
> unwinding and exception dispatch will not cross over a C stack frame.
>
> Is there any possible way to make this work? I realize that lobbing
> exceptions over the top of unsuspecting C code is questionable anyway,
> but this is a large existing code base and I don't have the option of,
> say, reworking everything in C++.
>
> I am using gcc-3.2, g++-3.2, libstdc++-3.2, and glibc-2.2.93 on a Red
> Hat Linux 8.0 box. Example code follows.
Yes. To do it, you have to compile the C code with "-fexceptions" to
generate appropriate unwind information.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer