Re: Tricks of the trade



Murray,

> It's an annoying aspect whenever you need to initialize a library, yes.
> Feel free to suggest a patch to avoid this.

I am not sure there is a patch that avoids the "problem" -- actually I
would be surprised if there is one or you and the team would almost
certainly already have thought of it!

Replacing the static member variable with a static method containing a
static local variable and returning a reference is a device for changing
the initialization sequence and so "solves" the problem at the expense
of using a method call rather than access to a variable but inlining the
method allows the compiler to generate code that is fairly efficient so
there should be no real runtime penalty.
 
> I suppose that you could initialize the type system from another of your
> static objects. I think that libxml++ uses a similar technique to
> initialize libxml. However, the order of initialization of static
> objects is not easily predictable and varies between platforms.

Which is probably the best argument for using the static method
technique.

Thanks for your (and others) responses on this, they have led me to a
working program.  Which is good.

-- 
Russel.
====================================================
Dr Russel Winder                +44 20 7585 2200
41 Buckmaster Road              +44 7770 465 077
London SW11 1EN, UK             russel russel org uk

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]