www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - idea for static class construction order

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
Was just thinking about it.  Why not just add it into the module's static
this()?

class A
{
public:
    static this() { ... }
}

class B
{
public:
    static this() { ... }
}

static this()
{
    static B.this();
    static A.this();
}

Are there any parsing / lex problems with this construct?  I'm just
wondering, as the order of static constructors has been undefined for a
while, and it'd kind of be nice to see it implemented.  :)
Dec 29 2004
parent reply "Matthew" <admin.hat stlsoft.dot.org> writes:
I kind of like this idea. Maybe the compiler could use the explicit order, if
provided, otherwise it would determine as 
it currently does.

"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message
news:cqvr91$2a4c$1 digitaldaemon.com...
 Was just thinking about it.  Why not just add it into the module's static
 this()?

 class A
 {
 public:
    static this() { ... }
 }

 class B
 {
 public:
    static this() { ... }
 }

 static this()
 {
    static B.this();
    static A.this();
 }

 Are there any parsing / lex problems with this construct?  I'm just
 wondering, as the order of static constructors has been undefined for a
 while, and it'd kind of be nice to see it implemented.  :)

 
Jan 21 2005
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
Wow, nice to see someone finally saw it :)
Jan 23 2005
parent "Matthew" <admin.hat stlsoft.dot.org> writes:
I'm on a gradual trawl through all the entries since the 3rd August. ;)

"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message
news:ct21v3$2pt2$1 digitaldaemon.com...
 Wow, nice to see someone finally saw it :)

 
Jan 23 2005
prev sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Matthew wrote:
 I kind of like this idea. Maybe the compiler could use the explicit order, if
provided, otherwise it would determine as 
 it currently does.
I agree that it would be a cool feature (though maybe I'm missing some unintended side effect). You can, of course, do it already; rather than declaring static constructors for the classes, simply define static functions which are called by the module constructor. I don't know how the ordering of module constructor and any (remaining) static class constructors interact, however. I guess it would be a good idea to explicitly state the order for all classes in a module where you care.
Jan 24 2005