Strategies for resolving cyclic dependencies in static ctors

Jacob Carlborg doob at me.com
Tue Mar 22 02:23:41 PDT 2011


On 2011-03-22 01:12, Nick Sabalausky wrote:
> At one point, I fiddled around with the idea of converting static ctors to
> "staticThis()" and then having one real static ctor for the entire library
> (assuming it's a library) that manually calls all the staticThis functions.
> One problem with this is that it's easy to accidentally forget to call one
> of the staticThis functions. The other big problem I found with this though,
> especially for a library, is that it requires everyone importing your code
> to always import through a single "import foo.all" module. If some user
> skips that, then the static ctors won't get run. There might be some
> possible workarounds for that, though:

One idea could be, although very platform dependent, to iterate the 
symbol table, finding all "staticThis" functions and calling them. Then 
you don't have the problem of forgetting to call one of those functions.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list