How do you debug @safe @nogc code? Can't figure out how to print.
aliak
something at something.com
Sun Nov 18 11:00:26 UTC 2018
On Saturday, 17 November 2018 at 21:56:23 UTC, Neia Neutuladh
wrote:
> On Sat, 17 Nov 2018 21:16:13 +0000, aliak wrote:
>> Could do. But it's not scalable. I'd have to comment out all
>> the unittests that call the template function with a T that
>> allocates inside the @nogc template (if I understood you
>> correctly that it)
>
> 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!
More information about the Digitalmars-d-learn
mailing list