__ctfe

Jonathan M Davis jmdavisProg at gmx.com
Tue Oct 2 00:53:58 PDT 2012


On Tuesday, October 02, 2012 09:45:10 Don Clugston wrote:
> On 01/10/12 21:30, Adam D. Ruppe wrote:
> > On Monday, 1 October 2012 at 19:22:37 UTC, Philippe Sigaud wrote:
> >> Something I wanted to ask for a long time: is there any runtime speed
> >> penalty in using __ctfe?
> > 
> > No. What happens is when it goes to the compile the runtime code, __ctfe
> > is a constant false, so then the optimizer can see it is obviously dead
> > code and eliminate the branch entirely. You don't even have to use the
> 
> > -O switch to get this:
> Yes, I was VERY careful about this. The "if (__ctfe)" branch gets
> discarded at the end of the front-end. The backend never sees it.

By the way, why is it not used in static if? That's what most of us would have 
expected (and it frequently seems to trip people up). I assume that it's due 
to some implementation detail of CTFE (like it doesn't really compile any 
functions differently for CTFE)?

- Jonathan M Davis


More information about the Digitalmars-d mailing list