How do you debug @safe @nogc code? Can't figure out how to print.

Vijay Nayar madric at gmail.com
Thu Nov 22 10:52:49 UTC 2018


On Sunday, 18 November 2018 at 11:00:26 UTC, aliak wrote:
> On Saturday, 17 November 2018 at 21:56:23 UTC, Neia Neutuladh 
> wrote:
>> On Sat, 17 Nov 2018 21:16:13 +0000, aliak wrote:
>>> [...]
>>
>> I meant something like:
>>
>>     void debugln(T...)(T args) @nogc
>>     {
>>       import std.stdio;
>>       debug(MyProject) writeln(args);
>>     }
>>
>> You use that function instead of writeln in your 
>> @nogc-compatible templates:
>>
>>     void callFunc(alias func)()
>>     {
>>       debugln("about to call function!");
>>       func();
>>       debugln("done calling function!");
>>     }
>>
>> Then I can write:
>>
>>     @nogc:
>>     void foo() { printf("hello world\n"); }
>>     void main() { callFunc!foo(); }
>
> Aha! I misunderstood what you meant. Yes that's actually 
> simpler that what I was doing :D Thanks!

Alternatively, you can use the core.stc libraries, which do not 
depend on the GC, for debugging.  
https://dlang.org/phobos/core_stdc_stdio.html#.printf


More information about the Digitalmars-d-learn mailing list