View mode: basic / threaded / horizontal-split · Log in · Help
October 11, 2005
calling a D function from within C
First of all thank you for the D programming language. I am still scoping it out
but it looks quite impressive.

I was looking for a way to call a D function from within C as part of a callback
routine. Any suggestions on how to do this?
October 11, 2005
Re: calling a D function from within C
"David Schere" <David_member@pathlink.com> wrote in message 
news:dih236$22er$1@digitaldaemon.com...
> First of all thank you for the D programming language. I am still scoping 
> it out
> but it looks quite impressive.
>
> I was looking for a way to call a D function from within C as part of a 
> callback
> routine. Any suggestions on how to do this?

In D, make a function and compile it with C linkage, like so:

extern(C) void fork()
{

}

Then give the address of that function to your C function..

someCFunctionThatTakesAFunctionPointer(&fork);

And it should work.

If you're looking to make a DLL or library in D that can be used in C, 
that's another story.
Top | Discussion index | About this forum | D home