D - template's static constructor
- Gennadi Pais (31/31) Aug 06 2003 Hi All,
- Mike Wynn (11/42) Aug 07 2003 have you tried
Hi All, could you explain me a following behavior of the D compiler/linker? I wrote something like: ______ in the module foo ______ .. template TTestStatic(T) { class Class { public static this () { printf ("static TTestStatic.Class.Ctor()\n"); } } } ______ in the module bar ______ private import c.stdio; private import foo; .. alias instance TTestStatic(int) TSI; .. int main () { printf ("Begin of the main function\n"); .. printf ("End of the main function\n"); return 0; } _________________________________ After the compilation there was no static constructor call... Ok... I've tried to solve it and when I added static constructor to any class in module "bar" (or another one) or just an empty class with static constructor I see the static Ctor of the template was called! Compiler is: Digital Mars D Compiler Beta v0.68 Thanks!
Aug 06 2003
have you tried adding TSI.class a; before main ? the linker will not need to link any code because nothing calls methods of class TTestStatic(int).Class there are no instances etc. "Gennadi Pais" <Gennadi_member pathlink.com> wrote in message news:bgqg8m$b5d$1 digitaldaemon.com...Hi All, could you explain me a following behavior of the D compiler/linker? I wrote something like: ______ in the module foo ______ .. template TTestStatic(T) { class Class { public static this () { printf ("static TTestStatic.Class.Ctor()\n"); } } } ______ in the module bar ______ private import c.stdio; private import foo; .. alias instance TTestStatic(int) TSI; .. int main () { printf ("Begin of the main function\n"); .. printf ("End of the main function\n"); return 0; } _________________________________ After the compilation there was no static constructor call... Ok... I've tried to solve it and when I added static constructor to anyclass inmodule "bar" (or another one) or just an empty class with staticconstructor Isee the static Ctor of the template was called! Compiler is: Digital Mars D Compiler Beta v0.68 Thanks!
Aug 07 2003