Mail Archives: djgpp/1997/08/01/20:32:47
"Art S. Kagel" (kagel AT ns1 DOT bloomberg DOT com) writes:
> On Sun, 27 Jul 1997, Darren Grant wrote:
>
>> Hello,
>>
>> How do I link my own extra entry/exit code into a c project?
>
> The function atexit() will let you define a hierarchy of functions to
> execute when the program is exiting either through return from main() or
> a call to exit() (the _exit() function skips atexit processing).
>
> For entry code you will either have to live with executing stuff at the
> beginning of main() or write a custom verstion of crt0.o the startup
> module.
The program I'm working on has custom startup stuff, and I didn't go
anywhere near those scary crt files. :-)
My secret: C++. A constructor in a dummy class (or, for that matter a
'real' one) will execute before main(). Some of my modules have a dummy
class whose constructor sets up global variables; one even reads a data
file from disk. These are triggered because there is a static module-level
variable of the dummy type in the module's implementation (.cc) file. This
way I can add modules that do this stuff without having to link all of
their headers in main and remember to add yet another "fooinit();" in main().
--
.*. Where feelings are concerned, answers are rarely simple [GeneDeWeese]
-() < When I go to the theater, I always go straight to the "bag and mix"
`*' bulk candy section...because variety is the spice of life... [me]
Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh
- Raw text -