delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/15/15:19:03

Message-Id: <m0xLTIV-000S1fC@inti.gov.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT gov DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT edu DOT ar>
Organization: INTI
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, blizzar AT hem1 DOT passagen DOT se
Date: Wed, 15 Oct 1997 16:32:12 +0000
MIME-Version: 1.0
Subject: Re: RHIDE Question.
CC: djgpp AT delorie DOT com

Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
 
> On Tue, 14 Oct 1997, Peter Palotas wrote:
> 
> > >This was discussed some time ago and nobody was able to show an example (of 
> > >logic code ;-) that really needs a sequence of compilation/link.
> > >Why do you want to tell an specific order? I only make a similar thing
> > >when I want to test the compilation of one file without compiling
> > > the rest first, for this there are an option to compile one file.
> > 
> > Well, I think I can give an example. I want to compile a file which outputs
> > a headerfile (.h). And this file is included in some of the .C* files that
> > I compile. (Compile might be the wrong work, but anyway... I use some AWK
> > scripts/programs and CPP to generate a headerfile from several others
> > anyway, and this has to be created *before* any of the other files are
> > compiled).
> 
> This should be done by Make.  Make will ensure that any target
> required to produce another target is made first.
> 
> 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.

SET 
------------------------------------ 0 --------------------------------
Visit my home page: http://www.geocities.com/SiliconValley/Vista/6552/
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Alternative e-mail: set-sot AT usa DOT net - ICQ: 2951574
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013

- Raw text -


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