digitalmars.D.learn - val.init
- Nick Sabalausky (8/8) Oct 01 2013 I thought variable.init was different from T.init and gave the value of
- Jacob Carlborg (4/6) Oct 01 2013 Yes.
- monarch_dodra (6/15) Oct 02 2013 AFAIK "variable.init" just triggers the "static call through
- Sean Kelly (5/14) Oct 02 2013 of
- Jacob Carlborg (5/6) Oct 02 2013 It has worked like this for as long as I can remember. I've been using D...
- Rene Zwanenburg (12/21) Oct 03 2013 Not exactly. The spec does mention something similar regarding a
- Nick Sabalausky (3/9) Oct 06 2013 Ahh, ok, I think that's what confused me.
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 }
Oct 01 2013
On 2013-10-02 04:10, 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?:Yes. -- /Jacob Carlborg
Oct 01 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 }AFAIK "variable.init" just triggers the "static call through instance" mechanic: The *variable* a doesn't actually have .init, so the call resolves to "int.init".
Oct 02 2013
On Oct 1, 2013, at 7:10 PM, Nick Sabalausky = <SeeWebsiteToContactMe semitwist.com> wrote:I thought variable.init was different from T.init and gave the value =ofthe explicit initializer if one was used. Was I mistaken?: =20 import std.stdio; void main() { int a =3D 5; writeln(a.init); // Outputs 0, not 5 }I think it used to work roughly this way but was changed=85 um=85 maybe = 2 years ago?
Oct 02 2013
On 2013-10-02 19:54, Sean Kelly wrote:I think it used to work roughly this way but was changed… um… maybe 2 years ago?It has worked like this for as long as I can remember. I've been using D for 6-7 years. -- /Jacob Carlborg
Oct 02 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
Oct 03 2013
On Thu, 03 Oct 2013 11:59:05 +0200 "Rene Zwanenburg" <renezwanenburg gmail.com> wrote:struct A { int i = 5; } void main() { writeln(A.init.i); } prints 5.Ahh, ok, I think that's what confused me.
Oct 06 2013