Re: Does g++ really need to compile main, if c++ code is involved?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(Accidentally didn't reply all the first time, sorry)

On 20-Mar-14 12:38, Jonathan Wakely wrote:
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.

I agree with this.


Global ctors/dtors are a separate issue, I'm not sure how they're
handled if main() isn't written in C++.


Shouldn't these be handled in crt*.o by being placed in .dtors/.ctors? As long as these are linked in by gcc/g++ then everything should be fine (as a matter of fact the C compiler lets you hook into this functionality using attributes IIRC, so it needs to provide that as well...).




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux