[Issue 3556] version(CTFE)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 3 14:30:43 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3556



--- Comment #1 from Don <clugdbug at yahoo.com.au> 2010-01-03 14:30:41 PST ---
Created an attachment (id=542)
Patch against DMD2 svn 324

Here is a patch which adds __ctfe as a 'magic variable'. It's a bool which is
true if evaluated in a function at compile-time, but false at run-time.
If evaluated outside a function, it gives a "non-constant expression" error.

Simple example:
---------
import std.stdio;

int foo() {
  if (__ctfe) return 3;  
  writefln("run-time evaluated");
  return 2;
}

static assert(foo()==3);

void main()
{
  assert(foo()==2);
}
--------

The back-end throws out the if(__ctfe){...} part (even without optimisations
turned on), so there is no runtime penalty for adding if(__ctfe) clauses.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list