Strategies for resolving cyclic dependencies in static ctors

Max Samukha max at spam.box
Tue Mar 22 09:15:38 PDT 2011


On 03/22/2011 04:14 PM, Michel Fortin wrote:
> On 2011-03-22 05:16:31 -0400, Max Samukha <max at spam.box> said:
>
>> ----
>> module foo_helper;
>>
>> private extern(C) foo_static_ctor();
>> static this()
>> {
>> foo_static_ctor();
>> }
>>
>> -----
>>
>> module foo;
>> import foo_helper;
>>
>> private Object global;
>> private extern(C) void foo_static_ctor()
>> {
>> global = new Object;
>> }
>> ----
>>
>> Note that "global" is guaranteed to have been initialized when
>> accessed from static constructors in modules that import "a".
>
> I don't know why people keep repeating that falacy.

It's not people, only me. It's embarrassing. I deserve to be processed 
in a bioreactor on a charge of utter incompetency.

Of course, you are absolutely right.

Then why we keep losing last bits of sanity inventing workarounds? The 
problem obviously has no safe solution in the context of D. People have 
been asking for a solution for a long time. There is an obvious need for 
it. So why not just give us that damn pragma?


More information about the Digitalmars-d mailing list