August 06, 2003 template's static constructor | ||||
|---|---|---|---|---|
| ||||
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!
| ||||
August 07, 2003 Re: template's static constructor | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Gennadi Pais | 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 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! > > | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply