Compile time function execution...
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Thu Feb 15 11:35:34 PST 2007
Michiel wrote:
> That's a great feature! A couple of questions, if I may:
>
> * Can sqrt still call another function?
According to the documentation in the zip, yes. But only functions which
can themselves be executed at compile time, of course.
> * Does it still work if classes or structs are involved in any way? What
> about enums? What about arrays?
Classes and structs seem to be disallowed.
Array and string literals can be used as parameters, as long as all
members would also be valid parameters by themselves. The body may not
use non-const arrays.
Enums aren't mentioned, but either they qualify as integers (meaning
they can be passes as parameters) or not. Either way, they're not
disallowed in the body so they should be usable there.
> * Why is the second sqrt(10) run at runtime? In theory it's still a
> constant, right? Is this something that will work in a later version?
From the spec:
"""
In order to be executed at compile time, the function must appear in a
context where it must be so executed, for example:
* initialization of a static variable
* dimension of a static array
* argument for a template value parameter
"""
So this is only done if it's used in a context where only compile-time
constants are allowed.
More information about the Digitalmars-d
mailing list