Interfacing with C - calling member function of D struct from C?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 24 19:09:53 PDT 2017
On Sunday, 25 June 2017 at 02:05:35 UTC, unleashy wrote:
> How would I call `addToBar` from C code?
You don't. Instead write it like:
struct Foo
{
int bar;
}
extern(C) void addToBar(Foo* foo, int what) {
foo.bar += what;
}
Then define it in C the same way and you call it the normal way
from C.
But from D, you can UFCS call it:
Foo* foo = new Foo();
foo.addToBar(5); // cool
though I'd prolly just call it from D the same way you do from C
too.
More information about the Digitalmars-d-learn
mailing list