Debugging by old fashioned trace log printfs / writefln

Cecil Ward cecil at cecilward.com
Fri Jun 30 15:43:14 UTC 2023


On Thursday, 29 June 2023 at 23:54:45 UTC, Chris Katko wrote:
> On Thursday, 29 June 2023 at 18:27:22 UTC, Cecil Ward wrote:
>> I’m trying to debug my D program with old-fashioned printfs 
>> stuck in various strategic places, actually using writefln(). 
>> My problem is that the addition of printf fights with the 
>> existing declarations for pure nothrow @nogc @safe and I have 
>> to adjust them, then put them back correctly when the 
>> writefln() trace statements are later removed.
>>
>> Is there something else I could be using, something that is 
>> allowed to violate the checking rules for purity, nothrow, 
>> @nogc? Would pragma( msg, "…" ) do the trick? Is that what I 
>> should be using?
>
> pragma(msg, "") is only for compile time. It for debugging 
> functions/templates if they're actually used (which static path 
> is used), instantiated, and you can also get type values from 
> template inputs to confirm they're what you expect. "Oh this is 
> a char[][] not a char[]!"
>
> pragmas are the D equivalent of C/C++ pragmas. In this case, 
> C/C++:
> ```C
> #pragma message( message-string )
> ```

Since I can pass my main function some compile-time-defined 
input, the whole program should be capable of being executed with 
CTFE, no? So in that case pragma( msg ) should suffice for a test 
situation? Would pragma(message) have the advantage over writefln 
that I don’t have to pervert the function attributes like nogc 
nothrow pure ?


More information about the Digitalmars-d-learn mailing list