This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: static constructors/destructors and atexit
- To: jbuck at synopsys dot com (Joe Buck)
- Subject: Re: static constructors/destructors and atexit
- From: Michael Gschwind <mikeg at watson dot ibm dot com>
- Date: Sat, 15 Aug 1998 09:21:31 -0400 (EDT)
- Cc: kamil at dwd dot interkom dot pl, jbuck at synopsys dot com, parkes at sierravista dot com, tv at pobox dot com, oliva at dcc dot unicamp dot br, egcs at cygnus dot com
> I think that we can assume that this other code is all C (you can't
> mix different C++ compilers), so it may have atexit calls but won't
> have any destructor calls.
>
> Since this other code will be calling the real atexit(), then the atexit()
> calls for the whole program may not be in the right order.
Here is a sample implementation how static destructors can be
implemented in a semi-sane standard conformant way:
register_destructor(funpter)
{
int atexitcode =0;
static int OK_toregister = 1;
if (OK_toregister)
atexitcode = at_exit(trampoline_for_destructor);
append_to_destructorlist (funptr, atexitcode);
}
trampoline_for_destructor()
{
*get_from_destructorlist(funptr)();
if (check_exitcode_for_next_destructor() == 0)
for (registered destructors)
*get_from_destructorlist()();
}
This code intersperses destructorcalss w/ other atexit calls while the
system lib can handle it, then pulls off the rest at the end...
m.
--
Michael K. Gschwind
IBM T.J. Watson Research Center phone (external): (914) 945-3162
PO Box 218 phone (internal): T/L 862-3162
Yorktown Heights, NY 10598 e-mail: mikeg@watson.ibm.com