|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
D - initialization of static fields
Just wondering what everybody thinks about being able to initialize static
fields like so:
class A
{
static int x = 0;
static int y = 3;
static this() {} // the above two initializations actually happen just
before entry to static this()
}
In C++, ambiguities with the pure syntax and with module initialization
order and linking problems cause this to not work. Seems simple enough
though. Of course, the default static this is usually empty, but the
compiler could tack on the initializations.
What about a similar syntax for initializing regular member fields?
class A
{
int x = 0;
int y = 3;
this() {} // the above two initializations actually happen just before
entry to this()
}
Of course the constructors are free to override these "defaults". I'm sure
it's easy enough for the compiler to figure out if the defaults aren't
needed, and obviously the programmer won't have to specify a default. It
might be nice to have the compiler warn about fields that are initialized in
more than one way, to prevent the situations like when one programmer
modifies the initialization inside the ctor and the other programmer
modifies the initialization at point of field declaration.
What about fields in structs? Can they have defaults? If structs could
have even "compiler-generated" constructors, it'd be real nice.
Sean
Nov 08 2001
"Sean L. Palmer" <spalmer iname.com> wrote in message news:9sdq5c$2bts$1 digitaldaemon.com... Nov 08 2001
"Pavel "EvilOne" Minayev" <evilone omen.ru> wrote in message news:9se608> > What about fields in structs? Can they have defaults? If structs couldhave even "compiler-generated" constructors, it'd be real nice. Nov 08 2001
|