How to make D libraries callable from C?
Alain
alainpoint at yahoo.fr
Tue Dec 19 00:11:51 PST 2006
== Quote from Brad Roberts (braddr at puremagic.com)'s article
> There's more to it than that.
> The D runtime will need to be initialized unless special care is
taken
> to avoid anything that's going to touch the GC or anything else that
> requires initialization. (it's been a while since I looked at that
part
> of phobos/ares.
> You'll have to be careful to keep the interfaces to mutually
compatible
> data types. D doesn't prevent you from writing something like:
> extern (C) char[] someFunc(SomeClass a, SomeAlias b,
SomeDelegate c)
> Essentially all the extern C part does is drop the name mangling.
> Don't let exceptions leak out of this D/C barrier.. C doesn't know
> anything about exceptions. If instead of C you really meant C++,
the
> same still applies except with dmd on windows. Every other
combination
> of language/compiler/os is currently incompatible, though I'd love
to
> see this fixed.
> There might be something else that needs to be handled as well, but
> those are the things that come to mind quickly.
> Later,
> Brad
All you warn me against seems reasonable. D being a higher-level
language than C, you have to down-grade it by writing a wrapper
around the D library in order to make it understandable by the C
application.
What i miss however is what you call the 'D runtime' initialisation.
Could you give a concrete example of what needs to be done.
Thanks in advance
Alain
More information about the Digitalmars-d
mailing list