Idea for C++ Interop

Craig Black cblack at ara.com
Sat Dec 23 07:10:31 PST 2006


"Andrey Khropov" <andkhropov_nosp at m_mtu-net.ru> wrote in message
news:emireg$krs$1 at digitaldaemon.com...
> Craig Black wrote:
>
> > I've been thinking about how to provide interoperability between D and
C++.
> > One idea I had was to compile C++ to C.  I've never used such a compiler
but
> > I'm fairly sure that they exist.
> >
> > Thoughts?
>
> But what benefit can you obtain from this compared to just extern "C" ?

You can't put an extern "C" around a C++ class or template.  A C++ to C
compiler would automatically convert ALL C++ code to C.  Then it could be
compiled with DMC, so that you have complete access to all your C++ API via
C.  The C++ to C conversion might bastardize some of your code, especially
the templated stuff.  But for some people, it may be worth a try.  It would
allow you to invoke ALL your C++ code from D, not just the stuff you make
extern "C" by hand.

>
> The problem is that C++ and D object models (and hence ABIs) aren't
completely
> compatible. So we have to stick to the lowest Common Denominator (C) or
use
> some component model like COM (it's already supported), CORBA, .NET CLR or
JVM.

Right, C.  Yes I know that.  That's why I suggested a C++ to C converter.

-Craig





More information about the Digitalmars-d mailing list