static init cycle detection problem

Jonathan M Davis jmdavisProg at gmx.com
Thu Sep 20 12:05:10 PDT 2012


On Thursday, September 20, 2012 20:49:32 Øivind wrote:
> Thanks for the explination. The trick you talk about has worked
> for me before, but now I really need static init of modules that
> depend on eachother. Only solution I can think of is to list all
> modules in a script and generate d code from this to call init
> functions.. Then pass it to dmd along with the other code.
> 
> Sad that we can't get this to work like it really should. D is a
> very flexible language in many ways, and it seems strange that it
> should not allow the stuff I want to do here..

If you have a true circular dependency, then you're just plain screwed and 
need to redesign your code. That's fundamental and _can't_ be fixed.

Off the top of my head, the only reason that you wouldn't be able to use the 
trick that std.stdio uses but not have a true circular dependency is if your 
initializing const or immutable variables in a static constructor. But then 
the solution is to refactor your code so that you don't have the circular 
dependency, even if it's just moving those variables into a separate module, 
which is generally quite feasible, even if it's not necessarily quite what you 
wanted.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list