← Back to team overview

kicad-developers team mailing list archive

Re: Damned the 'undefined global constructor order'

 

On 2014.06.09 19:56, Lorenzo Marcantonio wrote:
> How could I solve this?
> 
> Solution 1) explode in the presets the whole list of layers in TECH_FRONT. Not
> exactly elegant
> 
> Solution 2) convert the TECH_FRONT constant to a function which always return the
> correct value; best way to fix it I found until now (however every time
> it recomputes the whole or chain...)
> 
> Solution 3) the preset could be moved inside the only function using
> it... sadly not a general case solution
> 
> Solution 4) ??? anybody knows some idiomatic form/magic pattern to avoid
> the problem?
> 

A common solution to this problem is to never use global static
variables. Instead, create a function that contains a local static
variable of wanted type and returns a reference to it. The variable will
be constructed on the first invocation of the function. In this way all
invocations of such global "constructor functions" will be serialized as
the dependencies become explicit.

Cheers,
Povilas



Follow ups

References