Proposal: static ctor priority
Deewiant
deewiant.doesnotlike.spam at gmail.com
Thu Jun 21 01:35:59 PDT 2007
Daniel Keep wrote:
> Example:
>
> module a;
> import b;
>
> pragma(priority, 2)
> static this()
> {
> // Do stuff
> }
>
> module b;
> import a;
>
> // defaults to priority 1.
> static this()
> {
> // Do other stuff
> }
>
> (NB: modules are initialised from higher priority (int.max) to lowest
> (int.min))
>
> This would allow developers to manually break these cycles by specifying
> the relative order they should be initialised in. For bonus points,
> make this possible:
>
> module a;
> import b;
>
> pragma(priority, b+1)
> static this() {
> ...
>
> This should be much easier to implement than flow analysis, whilst still
> solving the problem.
>
> Comments?
We already have the parentheses after "static this", why not reuse them? We
don't need a pragma:
static this(1) { ... }
static this(2) { called before the above... }
static this() { called whenever... }
If we'll ever get more than one module constructor per module (I hope we will),
"b+1" priority would have to mean "max(all in b) + 1". Not a problem, just
making a note.
--
Remove ".doesnotlike.spam" from the mail address.
More information about the Digitalmars-d
mailing list