Summary: [CTFE] Fragile CTFE
           Product: D
           Version: 2.040
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-02-18 13:06:33 PST ---
This code (that uses CTFE to do something that can be useful, it initializes an
array with values compiled at compile time) compiles and works correctly, but I
think it's too much fragile: if you change the for loop a little, or other
details in genFactorials(), the program stops compiling:

int factorial(int n) {
    if (n == 0)
       return 1;
    return n * factorial(n - 1);

int[] genFactorials(int n) {
    int[] result;
    for (; n >= 0; --n)
        result = factorial(n) ~ result;
    return result;

const int N = 13;
static const auto factorials = cast(int[N])genFactorials(N - 1);
void main() {}

If you need them, I can show many variants of this program that don't
I think to be useful in real programs CTFE has to be less fragile than this.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to