Max Samukha wrote:
Michel Fortin wrote:


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.

If your module imports std.stdio, std.stdiobase's static constructor is guaranteed to run before your module's static constructors because your module depends on std.stdiobase indirectly via std.studio.

Max is correct. This is not a problem, because the dependency checking is transitive.

Reply via email to