Date: Wed, 15 Oct 1997 18:03:35 -0700 (PDT) Message-Id: <199710160103.SAA04722@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: "Salvador Eduardo Tropea (SET)" , Eli Zaretskii , blizzar AT hem1 DOT passagen DOT se From: Nate Eldredge Subject: Re: RHIDE Question. Cc: djgpp AT delorie DOT com Precedence: bulk At 04:32 10/15/1997 +0000, Salvador Eduardo Tropea (SET) wrote: >Eli Zaretskii wrote: >> However, I think I have a case where the link order really is >> important. This is when one or more of the modules being linked use >> functions with `__attribute__((constructor))' or ((destructor)). >> >> For example, imagine that a program uses Filesystem Extensions to >> install handlers for some special files, and uses the constructor >> attribute to make the installation happen before `main' gets called. >> >> These functions will be invoked by the startup/exit code in the order >> they are seen by the linker. And that order might be important, >> e.g. when one function needs to install itself ahead of others, so it >> sees the calls first. >I faced this problem with constructors of classes and library functions that >must be initialized before the constructor. I think the best way is to call the >initialization of the other module from the constructor. If the module is >already initialized it will return without making anything, if not is >initialized. The other way is to check if the module is initialized in each >function that's called externally. The last is a good practice and normally >isn't slow to add: > >XXXX >{ > if (!initialized) > initialize(); >} > >in the entry points. In this way you don't depend on the order of the link. Or how about this: void initialize(void) __attribute__((constructor)); void initialize(void) { initialize_first_piece(); initialize_second_piece(); /* ... */ } Nate Eldredge eldredge AT ap DOT net