Cyclic depency with class static ctor

Walter Bright newshound at digitalmars.com
Thu Oct 26 17:49:14 PDT 2006


Frank Benoit (keinfarbton) wrote:
> I have project with many classes which also sometimes have static ctors.
> Now I get the runtime error "cyclic dependency in module ...".
> 
> Is that a bug in the d runtime system, or is it just not documented,
> that this runtime error is also possible for static ctors?
> 
> Now I have these 300+ ported classes, in 300+ modules. And they import
> each other and many of them have a static ctor. What can I do? How can I
> resolve the problems?
> 
> I can think of the possibility to replace all "static this()" with a
> "public static void static_this()" and make a global module where i call
> all these ctor in a manual defined order. Is that the way to go?

Yes. It isn't possible for the language to really determine the 
dependencies, so it plays it safe and tries to get all the static ctors 
run before the module(s) static ctors that import them. With cyclic 
imports and static ctors in those cycles, this is not possible.



More information about the Digitalmars-d mailing list