@nogc

via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 12 03:55:31 PDT 2014


On Saturday, 12 July 2014 at 09:44:16 UTC, Piotr Szturman wrote:
> W dniu 2014-07-11 05:18, Kapps pisze:
>> On Friday, 11 July 2014 at 02:32:00 UTC, Manu via 
>> Digitalmars-d wrote:
>>> So, we allow assert() in nothrow functions, the argument is 
>>> that
>>> assert is non-recoverable, so it's distinct from user 
>>> exceptions.
>>>
>>> I have this in my 'nothrow @nogc' function:
>>>  assert(false, "Message " ~ details);
>>>
>>> It complains "Error: cannot use operator ~ in @nogc function"
>>>
>>> I think it should be allowed to invoke the GC for formatting 
>>> error
>>> messages inside of assert statements, just the same as 
>>> assert() is
>>> allowed inside of nothrow functions.
>>>
>>> Thoughts?
>>
>> More generally, I'm somewhat surprised that @nogc does not 
>> still allow
>> allocating Errors (including with assert), as who cares if 
>> your program
>> may slightly pause when it's about to crash in a theoretically
>> unrecoverable way.
>
> It does matter when entire program is marked with @nogc, so 
> there may be no GC code at all (GC code may not be linked).

Well, it wouldn't even link then...

But I think the more common route to go in such a case is to make 
a stubbed out GC that provides only allocation functionality 
(e.g. forwarding to malloc/free), but doesn't do any garbage 
collection. After all, some kind of memory allocation needs to 
present in almost all cases, it's just that it's done manually.


More information about the Digitalmars-d mailing list