static constructors/destructors and atexit
Michael Gschwind
mikeg@watson.ibm.com
Sat Aug 15 06:23:00 GMT 1998
> 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
More information about the Gcc
mailing list