Thread overview
How do I do printf/writefln debugging in CTFE?
May 13, 2012
Chad J
May 13, 2012
Dmitry Olshansky
May 13, 2012
Chad J
May 13, 2012
Hi,

It's been a while since I've used CTFE, and I was wondering if it has become possible to do something like this:


void ctfeFunc(string arg)
{
	pragma(msg, "arg is "~arg);
}

void main()
{
	ctfeFunc("foo");
}

That specific attempt gives me an error:
test.d(3): Error: variable arg cannot be read at compile time
"arg is " ~ arg

I'm using a git version of dmd that reads as v2.057.  I don't feel like upgrading thanks to bug 5278:
http://d.puremagic.com/issues/show_bug.cgi?id=5278
and the github situation where dmd, druntime, and phobos (and the docs?) all live in different github projects that aren't tracked collectively anywhere (last time I messed with it), thus making it sometimes frustrating to find buildable commits that will work with each other.

I want some way to print out the state of variables in a function being executed at compile time.  Can it be done?
May 13, 2012
On 13.05.2012 6:07, Chad J wrote:
> Hi,
>
> It's been a while since I've used CTFE, and I was wondering if it has
> become possible to do something like this:
>
>
> void ctfeFunc(string arg)
> {
> pragma(msg, "arg is "~arg);
> }
>
> void main()
> {
> ctfeFunc("foo");
> }
>
> That specific attempt gives me an error:
> test.d(3): Error: variable arg cannot be read at compile time
> "arg is " ~ arg
>
> I'm using a git version of dmd that reads as v2.057. I don't feel like
> upgrading thanks to bug 5278:
> http://d.puremagic.com/issues/show_bug.cgi?id=5278
> and the github situation where dmd, druntime, and phobos (and the docs?)
> all live in different github projects that aren't tracked collectively
> anywhere (last time I messed with it), thus making it sometimes
> frustrating to find buildable commits that will work with each other.
>
> I want some way to print out the state of variables in a function being
> executed at compile time. Can it be done?

Try pulling this guy (aka __ctfeWrite):
https://github.com/D-Programming-Language/dmd/pull/692

-- 
Dmitry Olshansky
May 13, 2012
On 05/13/2012 03:32 AM, Dmitry Olshansky wrote:
> On 13.05.2012 6:07, Chad J wrote:

>>
>> I want some way to print out the state of variables in a function being
>> executed at compile time. Can it be done?
>
> Try pulling this guy (aka __ctfeWrite):
> https://github.com/D-Programming-Language/dmd/pull/692
>

Cool, thanks!