Fixing cyclic import static construction problems
Jonathan M Davis
jmdavisProg at gmx.com
Wed Nov 28 22:42:10 PST 2012
On Thursday, November 29, 2012 07:36:41 Artur Skawina wrote:
> On 11/29/12 03:34, Walter Bright wrote:
> > Proposed Solution:
> >
> > Add a pragma,
> >
> > pragma(cyclic_imports);
> >
> > This can appear anywhere in a module, and applies globally to that module.
> > It means that static constructors from imports that are not part of the
> > cycle are run first, and that the static constructor for this module may
> > be run before the static constructors of other modules that are part of
> > the cycle.
> Bad name. Something like "module_ctors_unordered" would be better (I don't
> like that one either, but this way it's at least clear what it does).
no_cyclic_imports would probably be better given that you're trying to get
around a cyclic import, but I don't see what's unclear about cyclic_imports
given that that's exactly what the runtime complains about when this problem
occurs.
> but still has the problem that adding another module ctor
> can result is silent breakage.
That's actually a really good argument IMHO for having to put the pragma or
attribute on every single static constructor in a module. True, it may be a
bit annoying, but it would avoid silent breakage.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list