This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Does g++ really need to compile main, if c++ code is involved?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Eric Wolf <eric dot wolf at abas dot de>
- Cc: "Andy Falanga (afalanga)" <afalanga at micron dot com>, gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 20 Mar 2014 16:38:10 +0000
- Subject: Re: Does g++ really need to compile main, if c++ code is involved?
- Authentication-results: sourceware.org; auth=none
- References: <532AA680 dot 2050202 at abas dot de> <60F6FAE47D1BCE4380CC06D18F49789B93F2381A at NTXBOIMBX02 dot micron dot com> <532B0E4B dot 40305 at abas dot de>
On 20 March 2014 15:50, Eric Wolf wrote:
>
> I really think, static initializations and exceptions are the problem,
> because if I placed main in a C source file and compile it with gcc,
> how are the initializations done? How are uncaught exceptions handled?
Using the DWARF-based exception mechanism the compiler looks up the
stack for a suitable catch handler and if none is found (either
because the higher stack frames are C++ functions but don't catch the
exception, or because they are not C++ functions at all) then
std::terminate() is called at the throw site.
So I believe an uncaught exception will terminate the process
irrespective of what language main() is written in.
Global ctors/dtors are a separate issue, I'm not sure how they're
handled if main() isn't written in C++.