val.init
Rene Zwanenburg
renezwanenburg at gmail.com
Thu Oct 3 02:59:05 PDT 2013
On Wednesday, 2 October 2013 at 02:10:35 UTC, Nick Sabalausky
wrote:
> I thought variable.init was different from T.init and gave the
> value of
> the explicit initializer if one was used. Was I mistaken?:
>
> import std.stdio;
> void main()
> {
> int a = 5;
> writeln(a.init); // Outputs 0, not 5
> }
Not exactly. The spec does mention something similar regarding a
typedef [1]. Since typedef is deprecated I've never used it, but
IIRC it's effect is similar to defining a struct with a single
member. From this point of view it makes sense the init of a
typedef'ed primitive type is not necessarily equal to that
primitive type's init, since
struct A { int i = 5; }
void main() { writeln(A.init.i); }
prints 5.
[1] http://dlang.org/property#init
More information about the Digitalmars-d-learn
mailing list