anyway to debug nogc code with writeln?

aliak something at something.com
Mon Sep 3 13:57:46 UTC 2018


On Saturday, 1 September 2018 at 22:38:46 UTC, Ali Çehreli wrote:
> You can strip off any attribute with SetFunctionAttributes:
>
> import std.stdio;
>
> // Adapted from std.traits.SetFunctionAttributes documentation
> import std.traits;
> auto assumeNoGC(T)(T t)
>     if (isFunctionPointer!T || isDelegate!T)
> {
>     enum attrs = functionAttributes!T | FunctionAttribute.nogc;
>     return cast(SetFunctionAttributes!(T, functionLinkage!T, 
> attrs)) t;
> }
>
> void f(T)(auto ref T) {
>     writeln("yo");
> }
>
> @nogc void main() {
>     assumeNoGC(() => f(3));
>     // or
>     assumeNoGC( { writeln("yo"); });
> }
>
> Ali

Ah this works! Can define a debugWriteln then that can be used 
from anywhere without having to re attribute all the functions.

Thanks!


More information about the Digitalmars-d-learn mailing list