Specializing on Compile Time Constants

Fawzi Mohamed fmohamed at mac.com
Tue Oct 13 00:29:22 PDT 2009


On 2009-10-13 09:11:08 +0200, "Lars T. Kyllingstad" 
<public at kyllingen.NOSPAMnet> said:

> I may be wrong, but I seem to remember reading somewhere that DMD 
> always tries to evaluate as much as possible at compile time. That is, 
> if a function is CTFE-enabled, and its input is known at compile time, 
> it is calculated at compile time.
> 
>      void main(string[] args) {
>          auto x = foo(args[1]);  // foo() is evaluated at run time
>          auto y = bar("baz");    // foo() is evaluated at compile time
>      }

you are wrong, compile time evaluation is not performed if not 
requested (by making that constant for example).
The compiler cannot know the complexity of the calculation, and making 
it at compile time is much slower...
thus you have to explicitly instruct the computer to do it...




More information about the Digitalmars-d mailing list