Compile time function execution...

Walter Bright newshound at digitalmars.com
Thu Feb 15 14:46:30 PST 2007


torhu wrote:
> Walter Bright wrote:
>> This should obsolete using templates to compute values at compile time.
> 
> Wonderful feature, but look at this:
> 
> int square(int x)
> {
>    return x * x;
> }
> 
> const int foo = square(5);
> 
> al_id4.d(6): Error: cannot evaluate (square)(5) at compile time
> 
> 
> I was hoping this would make some C macros easier to replace, without 
> needing template versions for initializing consts.

Aggh, that's a compiler bug.

int foo = square(5);

does work. I knew I'd never get it right the first try :-(



More information about the Digitalmars-d mailing list