FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

static constructor issue:circular initialization dependency

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT
View previous topic :: View next topic  
Author Message
Shawn Liu



Joined: 09 Mar 2005
Posts: 104
Location: Shanghai, China

PostPosted: Wed Mar 30, 2005 3:08 am    Post subject: static constructor issue:circular initialization dependency Reply with quote

If two modules who has static constructor imports each other, an "circular initialization dependency " error occurs. This is a runtime error and can't detected at compile time (at least current version DMD can not).
To avoid this, Walter suggested that don't implement static initialization in both modules.

DWT has at least 3 or more modules with static constructor
display.d, os.d, widget.d ...

I think all static initialization should be done in os module, since user code (outside DWT) should never import os.d. This can avoid "circular initialization dependency" issue between DWT and user code.[/img]


Last edited by Shawn Liu on Wed Mar 30, 2005 10:25 pm; edited 2 times in total
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Wed Mar 30, 2005 10:08 am    Post subject: Reply with quote

Very good catch, Shawn. Those sections need their logic updated.
Back to top
View user's profile Send private message
Shawn Liu



Joined: 09 Mar 2005
Posts: 104
Location: Shanghai, China

PostPosted: Mon Apr 18, 2005 3:36 am    Post subject: Reply with quote

With more files added to project, call all those static ctor in OS becomes bothering. You must first import that module into OS module, the invoke the static ctor in static this() of OS. This make us fallible for forget to add some module's static ctor to OS module. There is another patient problem. OS module is used everywhere, but some module is seldom used or not used in some app. If we import all those module into OS. Can this increase the size of the executable file? I am not sure.

So, I prefer to call static ctor in its self module. Set a flag whether static ctor called before. And check the flag in static ctor. And invoke static ctor in all public ctor and public static motheds.

In this way, we can solove the "circular initialization dependency" and don't mess the OS module;
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group