Temporarily disable all purity for debug prints

Walter Bright newshound2 at digitalmars.com
Tue Apr 12 10:18:30 PDT 2011


On 4/12/2011 8:03 AM, Steven Schveighoffer wrote:
> use C linkage, you can do whatever you want. It's how druntime accomplishes a
> lot of stuff.
>
> For example:
>
> puredebug.d:
>
> import std.stdio;
>
> extern(C) void pureprint(string[] values...)
> {
> write("[pure debug] ");
> foreach(value; values)
> write(value);
> writeln();
> }
>
> puredebug.di:
>
> extern(C) void pureprint(string[] values...) pure;
>
> Should work.

Yes. But it occurs to me to take the subject title literally - allow impure code 
inside debug statements, as in:

pure void foo()
{
     debug writeln("in foo()");
}

Simple and effective.



More information about the Digitalmars-d mailing list