Ease of calling C code from D

Atila Neves atila.neves at gmail.com
Tue Jan 28 14:11:28 PST 2014


> Did you see Jacob's dstep too?

I think I read about it here in the forum at some point and 
somehow forgot about it. I'll definitely give it a go.

I also forgot to say that UFCS was pretty cool when dealing with 
C functions that take a pointer to a struct. Declaring it as ref 
in D worked too, which I was surprised about, i.e.

//C header
void doStuff(mystruct *foo, ...);

//D file
extern(C) void doStuff(ref mystruct, ...);
mystruct.doStuff(...);

Obviously "extern(C) void doStuff(mystruct*, ...);" also works 
but it's nice not to have to explicitly take the address of a 
struct to use it.

Atila

On Tuesday, 28 January 2014 at 20:12:35 UTC, Adam D. Ruppe wrote:
> On Tuesday, 28 January 2014 at 20:10:00 UTC, Atila Neves wrote:
>> There is htod but it's Windows only.
>
> Did you see Jacob's dstep too?
>
> https://github.com/jacob-carlborg/dstep
>
> I haven't actually used it myself* but it will surely do a 
> better job than the old htod!
>
> * I'm often really lazy with my calling of C code... I 
> translate as little as possible, sometimes just using void* 
> arguments instead of structs... when possible, of course.



More information about the Digitalmars-d mailing list