What the heck is wrong with CTFE's?

Marco Leise Marco.Leise at gmx.de
Mon Jul 8 17:12:43 PDT 2013


Am Tue, 09 Jul 2013 01:02:12 +0200
schrieb "JS" <js.mdnq at gmail.com>:

> Ultimately, the point is, that I thought CTFE's were suppose to 
> be compile time runnable functions. The problem is, the actual 
> language grammar changes. can use i++ as an argument to a 
> template at runtime without issue but not at compile time... and 
> since this seems to be the case from the examples I've posted, 
> this causes, at least for me, a lot of confusion. (who knows what 
> other differences there are) (and IMO they are flaws in the CTFE 
> system... although maybe there is some deep underlying reason why 
> it must be done that way)

If you look through the thread, others said that the behavoir
is the same in C at runtime. Your use of the ternary operator
is the problem. Only the branch that is taken is executed.
This should be obvious, but I agree that when the other branch
contains an i++ it looks like it should be executed. Please
look at the ternary operator as an if and else and it will
become clear why your increment works when you put it on a
separate line.

TL;DR: It has nothing to do with flaws in D or CTFE. At least
not this time around. ;)

-- 
Marco



More information about the Digitalmars-d mailing list