www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - calling a D function from within C

reply David Schere <David_member pathlink.com> writes:
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?
Oct 11 2005
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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.
Oct 11 2005