Understanding Safety of Function Pointers vs. Addresses of Functions
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 8 04:15:10 PDT 2015
On Wednesday, 8 July 2015 at 03:31:43 UTC, jmh530 wrote:
> I'm still not sure why I'm getting the error I mention in the
> original post. For instance, the code below is giving that
> Error 42 Symbol Undefined error. Seems very mystifying...
>
> import std.math : cos;
>
> real foo(T)(T fp, real x)
> {
> return fp(x);
> }
>
> void main()
> {
> real x = 0;
> real y = foo(&cos, x);
> }
It seems std.math.cos is an intrinsic function (i.e. one that the
compiler implements when needed, or generates the appropriate asm
for):
https://github.com/D-Programming-Language/phobos/blob/master/std/math.d#L630
The compiler should probably refuse to take the address of such a
function. I've found this bug report:
https://issues.dlang.org/show_bug.cgi?id=4541
More information about the Digitalmars-d-learn
mailing list