Compile time function execution...

Michiel nomail at please.com
Thu Feb 15 15:30:18 PST 2007


Jari-Matti Mäkelä wrote:

>>> 6) when the whole program is const foldable, e.i. no runtime inputs,
>>> like with some scientific software.
>>
>> And why would it be a problem if the whole program is reduced to
>> printing constants to the output? It would certainly be small and fast.
> 
> If the compiler generates a new instance of the algorithm whenever it is
> needed (i.e. function is partially evaluated), it can actually produce
> longer code than when simply calling the same function over and over.
> It's almost like inlining functions whenever possible.

That's actually not the idea. Basically, the idea is that the compiler
runs the algorithm and replaces every call to it with the answer. It's
possible (though unlikely), that the executable would be a bit larger,
but the executable would be much faster. And memory we have. In most
cases it's speed that's the problem.

-- 
Michiel



More information about the Digitalmars-d mailing list