delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/01/20:32:47

From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: custom entry/exit code
Date: 1 Aug 1997 06:12:53 GMT
Organization: The National Capital FreeNet
Lines: 33
Message-ID: <5rrup5$72k@freenet-news.carleton.ca>
References: <Pine DOT D-G DOT 3 DOT 91 DOT 970730090823 DOT 15307D-100000 AT dg1>
Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
NNTP-Posting-Host: freenet2.carleton.ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019