Re: typeid + toString = runtime error

2012-12-31 Thread monarch_dodra
On Monday, 31 December 2012 at 00:30:58 UTC, Andrej Mitrovic wrote: The basic rule is don't call or do anything which can allocate memory in a destructor. printf doesn't allocate, and if you don't do anything that allocates you should be ok. Does multi arg writeln even allocate? I don't

Re: typeid + toString = runtime error

2012-12-31 Thread Ali Çehreli
On 12/31/2012 03:30 AM, monarch_dodra wrote: // ~this() {writeln(typeid(this).toString, is dead);} // Fixed! ... right? If not, multy write? That still doesn't help with the case where e.g. a value has a special toString() defined and that toString() allocates memory. Such

Re: typeid + toString = runtime error

2012-12-30 Thread Ali Çehreli
On 12/30/2012 07:32 AM, Zhenya wrote: Hi! Explain me please why this code fails in runtime: import std.stdio; class Foo { ~this() {writeln(typeid(this).toString ~ is dead);} } void main() { new Foo; } Application error: core.exception.InvalidMemoryOperationError My guess is that by the

Re: typeid + toString = runtime error

2012-12-30 Thread Zhenya
On Sunday, 30 December 2012 at 16:04:48 UTC, Ali Çehreli wrote: On 12/30/2012 07:32 AM, Zhenya wrote: Hi! Explain me please why this code fails in runtime: import std.stdio; class Foo { ~this() {writeln(typeid(this).toString ~ is dead);} } void main() { new Foo; } Application error:

Re: typeid + toString = runtime error

2012-12-30 Thread Namespace
As far as I know this is because a class destructor is not a finalizer.

Re: typeid + toString = runtime error

2012-12-30 Thread Andrej Mitrovic
On 12/30/12, Zhenya zh...@list.ru wrote: Thank you,now all is clear for me. You can however use printf.

Re: typeid + toString = runtime error

2012-12-30 Thread Ali Çehreli
On 12/30/2012 08:11 AM, Namespace wrote: As far as I know this is because a class destructor is not a finalizer. Thanks. It is a good way of looking at this issue. Wikipedia describes the differences as Unlike destructors, finalizers are usually not deterministic. A destructor is run when

Re: typeid + toString = runtime error

2012-12-30 Thread FG
On 2012-12-30 17:04, Ali Çehreli wrote: Application error: core.exception.InvalidMemoryOperationError My guess is that by the time that destructor is executed, the runtime has been shut down sufficiently that the ~ operator cannot work. I've encountered this error before when using ~ in a

Re: typeid + toString = runtime error

2012-12-30 Thread Andrej Mitrovic
On 2012-12-30 17:04, Ali Çehreli wrote: Application error: core.exception.InvalidMemoryOperationError The basic rule is don't call or do anything which can allocate memory in a destructor. printf doesn't allocate, and if you don't do anything that allocates you should be ok. Maybe the compiler