== Quote from bearophile ([email protected])'s article > Regarding this: > Bugzilla 3556: version(CTFE) > I have written the following little D2 program: > import std.stdio: printf; > static if (__ctfe) { > int foo() { > return 1; > } > } else { > int foo() { > return 2; > } > } > enum int x1 = foo(); > void main() { > int x2 = foo(); > printf("%d %d\n", x1, x2); > } > But it doesn't work, I don't understand why. > (Isn't the usage of __ctfe normally done at compile time? Otherwise this > feature introduces another very special case in the language). > ---------------- > Can you tell me the purpose of the following 3 changes? > ModuleInfo changed from class to struct > added static/final function implementations to interfaces > http://dsource.org/projects/dmd/changeset/339 > Thank you, > bye, > bearophile
Because a compile-time __ctfe turned out to be almost impossible to implement. Therefore, __ctfe is nominally a regular (runtime) variable that evaluatest to true at compile time and false at runtime. The proper use is if(__ctfe), not static if(__ctfe). However, if(0) statements are thrown out by the code gen, so there should be no runtime performance hit for using if(__ctfe).
