Call C (or C++) with pointer to static function

Michael Stover michael.r.stover at gmail.com
Sun Oct 10 17:30:52 PDT 2010


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.

Can one call fortran libraries from D?  Ie, say one wanted to use LAPACK
from D?

Also, know of any mathematical libraries written in D (like implementations
of runge-kutta, linear algebra routines and data structures, optimization or
curve-fitting algorithms)?

-Mike



On Sun, Oct 10, 2010 at 5:10 PM, Simen kjaeraas <simen.kjaras at gmail.com>wrote:

> On Sun, 10 Oct 2010 22:03:51 +0200, Michael Stover <
> michael.r.stover at 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?
>>
>
> Absolutely. The dynamic compilation part is not directly supported, but
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101010/1d5641d2/attachment.html>


More information about the Digitalmars-d mailing list