I am under the impression that passing a pointer to a static function (ie, passing a pointer to a memory address that contains the starting point of a function) is not the same as defining a method that can be called by name from C code. I am not a C expert though.
Absolutely. The dynamic compilation part is not directly supported, butOn Sun, 10 Oct 2010 22:03:51 +0200, Michael Stover <michael.r.stover@gmail.com> wrote:
I am wondering if D would be a good choice for our differential equation
modeling app. What it needs to be able to do is dynamically compile D code
into a static function that can then be used to call C-code that expects a
pointer to a static function.
Longer description:
It is a desktop app. The user writes equations. I'd like to be translate
the equations into D code, compile it, and then call C code that represents
optimizing or solver procedures. These functions expect a pointer to a
static function that calculates the values of the equations, which would be
the D code just compiled.
Is this feasible with D2?
possible. There are several ways of accomplishing this, from Burton
Radon's (outdated, proof-of-concept only) dynamic compilation[1], to
calling the C functions in the generated D code, and pipe the output
where you need it.
Interfacing to C is detailed on this page:
http://digitalmars.com/d/2.0/interfaceToC.html
And can mostly be summarized like this:
Create a D function that is callable from C:
extern( C ) returnType myFunc( /* args */ ) {}
Refer to a C function that is callable from D:
extern( C ) returnType myFunc( /* args */ );
[1]: http://members.shaw.ca/burton-radons/The%20Joy%20and%20Gibbering%20Terror%20of%20Custom-Loading%20Executables.html
--
Simen