Compile-Time Functions - Allocating Memory?
Era Scarecrow
rtcvb32 at yahoo.com
Tue Jul 22 19:22:24 PDT 2008
I'm trying to compose as a test, where i fill a precompiled list of numbers in an array. What step am i missing to make this part work? (I i'm using gdc). it keeps complaining of a non-constant expression. Is there any way to make this work?
bool []primes = tp(1000);
bool [] tp( int max )
{
bool[] tmp = new bool[](max);
for ( int cnt = 2; cnt < max; cnt++ )
tmp[cnt] = isprime( cnt );
return tmp;
}
bool isprime( int x )
{
for ( int cnt = 2; cnt < x; cnt++ )
if ( x % cnt == 0 )
return false;
return true;
}
Era
More information about the Digitalmars-d-learn
mailing list