static constructors/destructors and atexit

Joe Buck jbuck@synopsys.com
Thu Aug 13 16:21:00 GMT 1998


I wrote:
> > We can conform to the standard simply by using atexit() to do local
> > static destruction.
> 
> Excuse me, but why complicate it so much? Why can't we simply make the
> compiler replace the user-level atexit() calls with our own atexit() with
> no limits? This way we would conform to the standard, right?

Yes, on platforms where we control the C library, or where atexit
is not crippled, that is the solution: just use atexit().

However, on some systems, atexit() is tightly integrated with the startup
function (the one that calls main() ), and it may be more difficult to
replace.  On Solaris, it appears that you would have to replace exit()
as well (since exit() calls the handlers registered by atexit()).  And
as someone pointed out, with shared libraries linked against libc it
might be difficult to force the replacement function to be called.







More information about the Gcc mailing list