Mail Archives: djgpp/1997/07/30/00:15:05
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.
- Raw text -