On Thursday, 31 December 2015 at 11:52:01 UTC, Shriramana Sharma
wrote:
Using DMD 2.0.69.2, the following code:
extern (C) double sqrt(double x);
enum q = sqrt(4.0);
gives the error:
Error: sqrt cannot be interpreted at compile time, because it
has no available source code
But if I do:
import std.math;
enum q = sqrt(4.0);
There is no problem. So two questions:
1) Why exactly can't the compiler call a C function at compile
time whereas it can call a D function?
2) <same as above> ... which itself only in the end calls that
very same C function IIANM?
I see druntime/import/core/math.d l 91:
double sqrt(double x); /* intrinsic */
No you can't call your own C function with CTFE. I do not say it
is not possible to implement this in dmd compiler, but IMHO it is
not something too much usefull