On 2010-03-11 05:22:38 -0500, Eldar Insafutdinov
<[email protected]> said:
Walter Bright Wrote:
Eldar Insafutdinov wrote:
The issue is that we need it in a performance critical part of QtD.
The library mixes in static constructors to initialise user-defined
classes. This means that we can't use it when user code is in cyclic
dependency. static constructors are very useful, but giving a
possibility to override it's current behaviour would make them
applicable to more use-cases(if you look into that bug report,
another person was trying to use them exactly as we do, and faced the
same problems).
I hear you. I'll try to come up with a better solution.
Thank you very much.
Yes, thank you.
I'd like to point out that the trick of creating a separate module to
initialize another one is not much safer than C++ static initialization.
Take for instance std.stdio which it is initialized by std.stdiobase's
static constructor. If your module import std.stdio and attempt to use
the standard input/output/error streams in a static constructor, there
is no guaranty that std.stdiobase static constructor will have been
called before yours (unless you also import std.stdiobase). It might
end up crashing depending on link order.
So it's a clever trick allowing you to bypass the safety checks, but
it's still dangerous, and it's not usable for templates and mixins.
--
Michel Fortin
[email protected]
http://michelf.com/