This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: order of constructors


On Tue, Dec 02, 2003 at 08:13:57PM -0500, Peter Barada wrote:
> 
> >> Peter Barada wrote:
> >> > Is there any way to control the order of static constructors so that
> >> > some that access other functions are done after those functions
> >> > intializing fucntions are done?
> >> 
> >> The C++ front end supports an init_priority attribute.  This is 
> >> documented in the manual.
> >
> >If you require portable C++ code, arranging that the static constructors
> >that have an order dependency are in the same file will enforce an ordering.
> 
> That's all well and good in a single file, but if I have constructors
> that refer to objects that an RTOS sets up(in its own libraries of
> course), I *have* to make sure that the RTOS library contructors are
> done before the applications constructors are done...

When this is necessary, my usual approach is to avoid relying on timing of
global constructors as much as possible, in favor of explicit
initialization functions and flags.  It's just too hard to get right.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]