Re: crash when using &this in struct constructor

2018-07-18 Thread Eric via Digitalmars-d-learn
On Wednesday, 18 July 2018 at 12:10:18 UTC, baz wrote: Specs are clear : it's a global so it's evaluated at compile time (https://dlang.org/spec/declaration.html#global_static_init) Example code should not compile. Indeed. Inside a function it does actually work. And ofcourse for class Tes

Re: crash when using &this in struct constructor

2018-07-18 Thread baz via Digitalmars-d-learn
On Wednesday, 18 July 2018 at 11:35:40 UTC, baz wrote: On Wednesday, 18 July 2018 at 11:27:33 UTC, baz@dlang-community wrote: On Monday, 16 July 2018 at 22:21:12 UTC, H. S. Teoh wrote: On Mon, Jul 16, 2018 at 10:08:34PM +, Eric via Digitalmars-d-learn wrote: [...] It's not illegal per se

Re: crash when using &this in struct constructor

2018-07-18 Thread baz via Digitalmars-d-learn
On Wednesday, 18 July 2018 at 11:27:33 UTC, baz@dlang-community wrote: On Monday, 16 July 2018 at 22:21:12 UTC, H. S. Teoh wrote: On Mon, Jul 16, 2018 at 10:08:34PM +, Eric via Digitalmars-d-learn wrote: [...] It's not illegal per se, but a very, very bad idea in general, because in D, s

Re: crash when using &this in struct constructor

2018-07-18 Thread baz@dlang-community via Digitalmars-d-learn
On Monday, 16 July 2018 at 22:21:12 UTC, H. S. Teoh wrote: On Mon, Jul 16, 2018 at 10:08:34PM +, Eric via Digitalmars-d-learn wrote: [...] It's not illegal per se, but a very, very bad idea in general, because in D, structs are expected to be int-like POD values that can be freely copied

Re: crash when using &this in struct constructor

2018-07-16 Thread Ali Çehreli via Digitalmars-d-learn
On 07/16/2018 03:08 PM, Eric wrote: This makes the compiler crash. Always a compiler bug: https://issues.dlang.org/show_bug.cgi?id=19089 Ali

Re: crash when using &this in struct constructor

2018-07-16 Thread Eric via Digitalmars-d-learn
On Monday, 16 July 2018 at 22:16:10 UTC, Adam D. Ruppe wrote: On Monday, 16 July 2018 at 22:08:34 UTC, Eric wrote: This makes the compiler crash. Is it illegal code? Yes, a struct can be moved at any time by the compiler which means pointers to it can be invalidated at random. Unless you al

Re: crash when using &this in struct constructor

2018-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 16, 2018 at 10:08:34PM +, Eric via Digitalmars-d-learn wrote: > This makes the compiler crash. Is it illegal code? > > struct List { > private List* head; > private List* tail; > > this(int x) { > head = null; > tail = &this; // <-- crasher > } > } > > List2 ls =

Re: crash when using &this in struct constructor

2018-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 16 July 2018 at 22:08:34 UTC, Eric wrote: This makes the compiler crash. Is it illegal code? Yes, a struct can be moved at any time by the compiler which means pointers to it can be invalidated at random. Unless you always allocate it externally yourself...

Re: crash when using &this in struct constructor

2018-07-16 Thread Eric via Digitalmars-d-learn
Pasted slightly wrong code, last line should be: List ls = 2; Question still stands.

crash when using &this in struct constructor

2018-07-16 Thread Eric via Digitalmars-d-learn
This makes the compiler crash. Is it illegal code? struct List { private List* head; private List* tail; this(int x) { head = null; tail = &this; // <-- crasher } } List2 ls = 2;

Re: this() in struct

2012-10-09 Thread Zhenya
On Tuesday, 9 October 2012 at 19:04:40 UTC, Jonathan M Davis wrote: On Tuesday, October 09, 2012 20:09:56 Zhenya wrote: Ok.Then can I do my own .init property that can be executed in compile-time? No. You directly initialize the member variables to what you want them to be, and that's the val

Re: this() in struct

2012-10-09 Thread Jonathan M Davis
On Tuesday, October 09, 2012 20:09:56 Zhenya wrote: > Ok.Then can I do my own .init property that can be executed in > compile-time? No. You directly initialize the member variables to what you want them to be, and that's the values that they have in the init property. You can't have anything li

Re: this() in struct

2012-10-09 Thread Zhenya
On Tuesday, 9 October 2012 at 18:29:18 UTC, Jonathan M Davis wrote: On Tuesday, October 09, 2012 19:08:35 Zhenya wrote: On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote: > Hi! > I'm sorry,maybe this topic already was discussed,but could > anybody explain me > why default constructor was

Re: this() in struct

2012-10-09 Thread H. S. Teoh
On Tue, Oct 09, 2012 at 07:08:35PM +0200, Zhenya wrote: > On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote: > >Hi! > >I'm sorry,maybe this topic already was discussed,but could anybody > >explain me why default constructor was disallowed in structs? > > And if I have to do some initializat

Re: this() in struct

2012-10-09 Thread Zhenya
On Tuesday, 9 October 2012 at 18:29:18 UTC, Jonathan M Davis wrote: On Tuesday, October 09, 2012 19:08:35 Zhenya wrote: On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote: > Hi! > I'm sorry,maybe this topic already was discussed,but could > anybody explain me > why default constructor was

Re: this() in struct

2012-10-09 Thread Jonathan M Davis
On Tuesday, October 09, 2012 19:08:35 Zhenya wrote: > On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote: > > Hi! > > I'm sorry,maybe this topic already was discussed,but could > > anybody explain me > > why default constructor was disallowed in structs? > > And if I have to do some initiali

Re: this() in struct

2012-10-09 Thread Ali Çehreli
On 10/09/2012 10:08 AM, Zhenya wrote: On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote: Hi! I'm sorry,maybe this topic already was discussed,but could anybody explain me why default constructor was disallowed in structs? And if I have to do some initialization of data members,what is t

Re: this() in struct

2012-10-09 Thread Maxim Fomin
On Tuesday, 9 October 2012 at 17:32:35 UTC, Zhenya wrote: On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote: Hi! I'm sorry,maybe this topic already was discussed,but could anybody explain me why default constructor was disallowed in structs? And if I have to do some initialization of

Re: this() in struct

2012-10-09 Thread Zhenya
On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote: Hi! I'm sorry,maybe this topic already was discussed,but could anybody explain me why default constructor was disallowed in structs? And if I have to do some initialization of data members,what is the way to do it?

this() in struct

2012-10-09 Thread Zhenya
Hi! I'm sorry,maybe this topic already was discussed,but could anybody explain me why default constructor was disallowed in structs?