Date: Wed, 30 Jul 1997 16:16:36 +1100 From: Bill Currie Subject: Re: custom entry/exit code In-reply-to: <33DC0947.605F@xl.ca> To: djgpp AT delorie DOT com Message-id: <199707300421.QAA07681@teleng1.tait.co.nz gatekeeper.tait.co.nz> Organization: Tait Electronics Limited MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Comments: Authenticated sender is Precedence: bulk On 27 Jul 97 at 19:51, Darren Grant wrote: > Hello, > > How do I link my own extra entry/exit code into a c project? > The easiest way is to use gcc's constructor and destructor attributes. ie: static void __attribute__((constructor)) entry_function(void) { /*do init stuff */ } static void __attribute__((destructor)) exit_function(void) { /* do uninit stuff */ } These functions will be called before main and after exit, respectively (exit is called with main's return value). If you have several object files with constructor/destructor functions, the order they are called in is determined by the link order. I don't know whether destructors are called in forward or reverse order, but the constructors are called in same order that the object files are specified on the linker command line. Bill -- Leave others their otherness.