recursive function call at compile time

bearophile bearophileHUGS at lycos.com
Sun Dec 16 09:49:59 PST 2012


Oleg:

> at compile time i have errors
> ./recursion.d(7): Error: index 4294967295 overflow for static 
> array
> ./recursion.d(7): Error: index 4294967294 overflow for static 
> array
> .... etc

It prints a little too many of those...


> call 'recursionAlgo()' where it should not be ( K == 1 )

The first problem to fix in your code is visible here, it's not a 
CTFE problem:


struct MyStruct(uint K) {
     real[K] data;

     auto getSmaller() {
         MyStruct!(K - 1) ret;
     }
}

void main() {
     MyStruct!5 a;
}


When you instantiate MyStruct!5, it tries to define ret, so it 
instantiates MyStruct!4, MyStruct!3, ... and so on. You have to 
put a static if or something else to stop that.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list