Use of atexit for destructors on Solaris 7.
Charles Galambos
c.galambos@eim.surrey.ac.uk
Thu Mar 23 08:02:00 GMT 2000
Hi,
> > Since 'atexit' on solaris is function ptr it can be replaced.
>
> Why do you think it is a function pointer? It is a proper function. It
> still can be replaced.
My mistake, its not a ptr. Just an overly quick glace at the systems headers
and wishfull thinking on my part.
> > Is there a way I can replace the atexit function before or at least
> > early in the initilisation of static variables ?
>
> You can provide a different version to linker. Depending on how
> exactly you arrange that, it will be used instead of the one in the C
> library. Of course, you'll also have to replace exit if you want the
> registered functions to be called...
Replacing 'atexit' and '_exithandle' functions seems to work nicely. In
one (medium-sized) program I tried, 'atexit' was called 149 times. Only 3 or
4
of these were calls made directly by the user. It does put the previous
limit in perspective.
> > wasn't silently ignored, especailly as most implementations seem to
> > have a limit of the the number of times it can be called.
>
> Why would that be good? If you have code like
If the compiler is going to do something unexpected, I'd like
to know. I could well be relying on a destructor to close a network
connection cleanly or something similar. If its not going to get called,
I'd like to know.
> MyClassC &AVar() { static MyClassC x; return x; }
>
> it typically matters in which order these variables are initialized -
> in many cases, it does not really matter in which order/whether they
> are destroyed. In your case, what would happen if some of these global
> objects are not destroyed?
Wouldn't bother me at all in this case. Which is why I was unaware
of the problem for so long. The problem only bit me when I started
using gtk, and the initalisation failed on a called to 'atexit'. All
the atexit calls were used before 'main' was even started. It
had me completely puzzled or a while... until I fired up gtk and
did a break on atexit.
I have a workable fix for now. I get the impression there is some work
being done on the 'atexit' mechanism to support dynamic libraries, I
assume this limit will be removed when this is introduced ???
Thanks,
Charles.
More information about the Gcc-bugs
mailing list