How to create C function pointers

Mildred mildred593 at online.fr
Thu Sep 7 06:51:27 PDT 2006


Hi,

In my application, I want to be able to extand it using regular C
objects, loaded using for example dlfcn for POSIX systems (maybe
another way on Windows).
So, I need to have C functions pointers but I don't know how to declare
them correctly :

/////////// test.d ///////////

module test;

extern(C){
    int c_function(int param){
        return param;
    }
}

int main(){
    // create a pointer to c_function
    extern (C) int function(int) ptr = &c_function;
    extern (C) int (*ptr2)(int)      = &c_function;
    return 0;
}

//////////////////////////////

$ dmd test.d
test.d(35): cannot implicitly convert expression (& c_function) of type
int(C *)(int param) to int(*)(int)
test.d(36): cannot implicitly convert expression (& c_function) of type
int(C *)(int param) to int(*)(int)

So, How do we do that , I did not find neither on the documentation nor
while browsing the web for the solution.
Thanks

Mildred

-- 
Mildred       <xmpp:mildred at jabber.fr> <http://mildred632.free.fr/>
Clef GPG :    <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]



More information about the Digitalmars-d mailing list