On Mon, 11 Apr 2011 17:27:41 -0400, bearophile <bearophileh...@lycos.com>
wrote:
From what I am seeing, in a D2 program if I have many (tens or more)
pure functions that call to each other, and I want to add (or activate)
a printf/writeln inside one (or few) of those functions to debug it, I
may need to temporarily comment out the "pure" attribute of many
functions (because printing can't be allowed in pure functions).
As more and more D2 functions become pure in my code and in Phobos,
something like a -disablepure compiler switch (and printf/writeln inside
debug{}) may allow more handy debugging with prints (if the purity is
well managed by the compiler then I think disabling the pure attributes
doesn't change the program output).
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.
-Steve