Debug prints in @nogc

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 30 04:42:29 PDT 2016


On 30/08/2016 11:10 PM, Nordlöw wrote:
> On Tuesday, 30 August 2016 at 10:36:13 UTC, rikki cattermole wrote:
>> On 30/08/2016 10:26 PM, Nordlöw wrote:
>>> I'm struggling with debug printing in my @nogc-containers.
>>>
>>> The alternatives:
>>>
>>>     assert(false, "Fixed message with no parameters");
>>>
>>> is not enough for my needs
>>>
>>>     debug writeln("Fixed");
>>>
>>> doesn't bypass @nogc checking. Why?
>>>
>>> And temporary commenting out @nogc is cumbersome.
>>>
>>> I'm aware of C-style printf but that is not as flexible as writeln.
>>>
>>> Any advice?
>>
>> Static array + formattedWrite, perhaps?
>
> I can't grasp how to use this from the docs at
>
> https://dlang.org/library/std/format/formatted_write.html
>
> uint fwrite(A...)(A a)
> {
>     import std.stdio : LockingTextWriter;
>     import std.stdio : stdout;
>     import std.format : formattedWrite;
>     return formattedWrite!(stdout.lockingTextWriter)(a);
> }
>
> LockingTextWriter is not publicly exported from std.stdio and
> stdout.lockingTextWriter can not be read at compile-time.
>
> Help please.

I fixed your code but lockingTextWriter is not @nogc.

void main() @nogc {
      import std.stdio : stdout;
      import std.format : formattedWrite;
      formattedWrite(stdout.lockingTextWriter, "%x", 7);
}

Okay looks like formattedWrite isn't @nogc able. Oh wells thought it was.
Please create an issue as this is quite an important feature.


More information about the Digitalmars-d-learn mailing list