CTFE question

Chris Cain clcain at uncg.edu
Tue Aug 28 04:29:30 PDT 2012


On Tuesday, 28 August 2012 at 11:13:40 UTC, Danny Arends wrote:
> Is this a bug or am I doing something wrong ??
>
> Danny Arends
> http://www.dannyarends.nl

You're doing something wrong, but I can see why the error message 
would confuse you.

Your problem is using those pragma(msg, ...) lines... They 
produce a message while something is being compiled, right? The 
CTFE function is ran _after_ it has been compiled. Hence i can't 
be read while the CTFE function is compiled.

So, to be clear, doing this:


-----

import std.stdio;
import std.metastrings;

pure int[] testCTFE(){
   int[] r;
   pragma(msg, "Testing CTFE");
   foreach(i; 0 .. 360){
     r ~= i;
     //pragma(msg, Format!("Loop: %d",i));
   }
   pragma(msg, "Done CTFE test");
   return r;
}

immutable CTFEdata = testCTFE();
immutable CTFEdata2 = testCTFE();

void main(string[] args){ }

----

Produces just one output:
Testing CTFE
Done CTFE test


Because the pragmas are done _as it's compiled_, not as it's ran 
(even though CTFE is done "at compile time").


More information about the Digitalmars-d-learn mailing list