Yes it is possible. In fact this is one of the main feature of dmd. To call a D function from C, just make that function `extern©`, e.g.
// .d
import std.c.stdio;
extern © {
shared int x; // Globals without 'shared' are thread-local in D2.
// You don't need shared in D1.
void increaseX() {
++ x;
printf("Called in D code\n"); // for some reason, writeln crashes on Mac OS X.
}
}
<!-- -->
// .c
#include <stdio.h>
extern int x;
void increaseX(void);
int main (void) {
printf("x = %d (should be 0)\n", x);
increaseX();
printf("x = %d (should be 1)\n", x);
return 0;
}
See [*Interfacing to C*](
[To see links please register here]
) for more info.