Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
December 23, 2006 Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
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? -Craig |
December 23, 2006 Re: Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Craig Black | 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?
>
> -Craig
>
>
An interesting note, IIRC Walter's C++ compiler was the first that didn't do this.
|
December 23, 2006 Re: Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Craig Black | 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" ? 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. -- AKhropov |
December 23, 2006 Re: Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey Khropov | > 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. Yes. As an example, GCC has CNI (http://gcc.gnu.org/onlinedocs/gcj/About-CNI.html) which supposedly allows one to "write Java native methods using C++." But it has a few restrictions on what types of class member variables you can have, and what classes you can derive from etc just to try and match the object models. Still its kinda cool. As for benefit over extern "C", I for one would love to be using Trolltech's Qt and some of the KDE4 libraries without having to wrap each release. Of course that would be shifting the insanity of dealing with the C++/D mismatch to D compiler writers. - Paul |
December 23, 2006 Re: Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Craig Black | Craig Black escribió: > 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? > > -Craig > > I posted this on 2004-05-02, so I don't know if any changes have been made since then: ---- OP ---- g++ seems to do a different name mangling than dmc, so this only works on windows. [file: test1.cpp] #include <stdio.h> void foo() { printf("Hi from C++\n"); } [file: test2.d] extern (C++) void foo(); void main() { foo(); } > dmc -c test1.cpp > dmd test2.d test1.obj ---- End OP ---- So, if things remain the same, I guess you can compile your project with DMC and have interoperability right away. -- Carlos Santander Bernal |
December 23, 2006 Re: Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey Khropov | "Andrey Khropov" <andkhropov_nosp@m_mtu-net.ru> wrote in message news:emireg$krs$1@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 |
December 23, 2006 Re: Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander | That's the implication that I was trying to communicate when I said "C++ to C" compiler. -Craig "Carlos Santander" <csantander619@gmail.com> wrote in message news:emjd06$170f$1@digitaldaemon.com... > Craig Black escribió: > > 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? > > > > -Craig > > > > > > I posted this on 2004-05-02, so I don't know if any changes have been made since > then: > > ---- OP ---- > > g++ seems to do a different name mangling than dmc, so this only works on windows. > > [file: test1.cpp] > #include <stdio.h> > void foo() { printf("Hi from C++\n"); } > > [file: test2.d] > extern (C++) void foo(); > void main() { foo(); } > > > dmc -c test1.cpp > > dmd test2.d test1.obj > > ---- End OP ---- > > So, if things remain the same, I guess you can compile your project with DMC and > have interoperability right away. > > -- > Carlos Santander Bernal |
December 26, 2006 Re: Idea for C++ Interop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Craig Black | Craig Black escribió: > 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? See Lightweight C++: http://students.ceid.upatras.gr/~sxanth/lwc/ -- Leandro Lucarella Integratech S.A. 4571-5252 |
Copyright © 1999-2021 by the D Language Foundation