CTFE with C functions not possible?

Shriramana Sharma via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 31 03:52:01 PST 2015

Using DMD, 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 */

Shriramana Sharma, Penguin #395953

More information about the Digitalmars-d-learn mailing list