CTFE with C functions not possible?
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 31 03:53:57 PST 2015
On 01/01/16 12:52 AM, 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 */
From what I've been able to tell, std.math have some special yucky
rules about it and intrinsics.
It will make it very hard to split std.math up.
More information about the Digitalmars-d-learn
mailing list