How to make D libraries callable from C?
Tomas Lindquist Olsen
tomas at famolsen.dk
Tue Dec 19 00:21:27 PST 2006
Alain wrote:
> == 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
The Win32 DLL in D article at digitalmars.com sums it up pretty well I
think:
http://www.digitalmars.com/d/dll.html
--
More information about the Digitalmars-d
mailing list