access CTFE variables at compile time.
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 9 21:46:14 PDT 2013
On Wednesday, July 10, 2013 06:24:02 JS wrote:
> On Wednesday, 10 July 2013 at 01:10:37 UTC, Meta wrote:
> > On Tuesday, 9 July 2013 at 22:49:38 UTC, JS wrote:
> >> It seems possible that we can print CTFE variables at compile
> >> time by using string mixes as the code below demonstrates.
> >>
> >> The problem is that we can not pass a variable to a template
> >> to create a print routine in the first place. e.g., we can't
> >> do mixin a!(s) if s is a string since s can't be read,
> >> supposedly, at compile time.
> >
> > I think there's been mention a couple times of a ctfeWrite
> > function that can print values at compile-time, but so far
> > nobody's implemented it.
>
> I've heard of this too and even tried __ctfeWrite and it worked!!
> Well, at least no compile time error... just didn't print
> anything.
>
> I believe the error "variable can't be read at compile time" is
> due to the fact that the compiler doesn't have access to/isn't
> aware of the frame pointers(the stack) of the functions. This
> means that "local" variables can't be used in compile time,
> before ctfe, constructs because there is no way to get at the
> data.
>
> This seems like a limitation of the system and not some innate
> reason why it should fail...
Making it work would be like trying to make an if function as a static if. It
would muddle things considerably and as such is a very bad idea IMHO. Right
now, there is a very clean distinction between what's done at compile time and
what's done at runtime as well as between CTFE and templated code. Allowing
what you're trying to do would ruin that.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list