Compile time function execution...

Michiel nomail at please.com
Thu Feb 15 16:25:52 PST 2007


Walter Bright wrote:

>>>>> Many functions could be executed at compile time, but should not be.
>>>> When should they not be?
>>> 1) Another poster mentioned a function that decompressed a built-in
>>> string - the whole point of having it compressed was to reduce the exe
>>> file size. Decompressing it at compile time defeats the purpose.
>>
>> Yes, that one was mentioned by Bill Baxter. But I think this is the
>> exception rather than the rule. The programmer could explicitly tell the
>> compiler to not execute that piece of code at runtime.
> 
> The programmer *already* has explicit control over whether it is folded
> or not.

Correction, I meant to say: "The programmer could explicitly tell the
compiler to not execute that piece of code at *compile time*."

And yes, the programmer already has explicit control. But not the way I
mean. Right now, in places where a call could potentially be either a
runtime- or compiletime- execution:

* the compiler defaults to runtime execution. And like I said, that
behavior isn't wanted in most cases (when compiling for release). I
would suggest defaulting to compile time execution and using a special
keyword to avoid that. The programmer will use this keyword if he's
compressed some data and wants it to be decompressed at runtime.

* the syntax for functions to be executed at compile time isn't the
nice-and-simple D syntax, but the template-syntax. And in another thread
you yourself have mentioned why that's not optimal. I agree.

-- 
Michiel



More information about the Digitalmars-d mailing list