Message-ID: From: Shawn Hargreaves To: djgpp AT delorie DOT com Subject: Re: startup functions on gnu c/c++? Date: Tue, 14 Apr 1998 10:41:40 +0100 MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk > How to I define functions to be called on program startup before main > is called? The only portable way to do this is to write in C++ and make your function be the constructor for a global object. There is a non-standard gcc extension, the 'constructor' function attribute, which can be used to do this with a normal C routine, but it probably isn't a good idea to rely on this unless you are 100% certain that your code will never need to be ported to any other compilers. In most cases where you might wish to use such a routine, I think it would actually be better to make an explicit call to the setup code from the start of main(), or store a 'firsttime' flag in your module which it can use to automatically initialise itself the first time it gets called. See 'info gcc "c extensions" "function attributes"' for details about how to set up a constructor function. Shawn Hargreaves.