static constructors/destructors and atexit

Joe Buck jbuck@synopsys.com
Tue Aug 11 22:43:00 GMT 1998


> As someone mentioned, this is not standards-conforming.  The standard
> requires that local static destruction be interleaved with atexit()
> callbacks and this won't do that.

We can conform to the standard simply by using atexit() to do local
static destruction.  On systems that restrict atexit to 32 handlers,
we can then handle at most 32-N local static variables that have
destructors.  So we conform but have a rather low limit as to size
of problem.  There can then be a flag to handle larger numbers of
destructors in a non-standard-conformant way (just do them in reverse
order of construction, ignoring atexit).

This number can be increased somewhat by using the as-if rule.  If there is
a destructor, but it has no side effects (and we know this because the
body is inline), it can be destroyed by some other mechanism than atexit.



More information about the Gcc mailing list