Understanding Safety of Function Pointers vs. Addresses of Functions
jmh530 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 8 08:49:13 PDT 2015
On Wednesday, 8 July 2015 at 14:37:23 UTC, jmh530 wrote:
> Thanks. I was worried I was doing something wrong.
It seems like if you wrap the intrinsic function in another
function than it works fine (below). Easy enough work-around, I
suppose.
If there is no intention to fix the pointer to assembly function
issue (I have zero clue how to go about it, maybe there is a good
reason it can't be fixed), this work-around could be implemented
in the std.math library for those functions. I.e., put the
assembly code in separate functions and then have the existing
intrinsic functions act as wrappers to those.
import std.math : cos;
real cos_wrap(real x) pure nothrow @nogc @safe
{
return cos(x);
}
void main()
{
auto fp = &cos_wrap;
real x = 0;
real y = fp(x);
}
More information about the Digitalmars-d-learn
mailing list