digitalmars.D - Idea for C++ Interop
- Craig Black (5/5) Dec 22 2006 I've been thinking about how to provide interoperability between D and C...
- BCS (3/11) Dec 22 2006 An interesting note, IIRC Walter's C++ compiler was the first that
- Andrey Khropov (7/12) Dec 23 2006 But what benefit can you obtain from this compared to just extern "C" ?
- Paul Findlay (11/14) Dec 23 2006 Yes. As an example, GCC has CNI
- Craig Black (16/26) Dec 23 2006 C++.
- Carlos Santander (17/28) Dec 23 2006 I posted this on 2004-05-02, so I don't know if any changes have been ma...
- Craig Black (9/37) Dec 23 2006 That's the implication that I was trying to communicate when I said "C++...
- Leandro Lucarella (6/11) Dec 26 2006 See Lightweight C++: http://students.ceid.upatras.gr/~sxanth/lwc/
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
Dec 22 2006
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? -CraigAn interesting note, IIRC Walter's C++ compiler was the first that didn't do this.
Dec 22 2006
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
Dec 23 2006
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
Dec 23 2006
"Andrey Khropov" <andkhropov_nosp m_mtu-net.ru> wrote in message news:emireg$krs$1 digitaldaemon.com...Craig Black wrote:C++.I've been thinking about how to provide interoperability between D andbutOne idea I had was to compile C++ to C. I've never used such a compilerYou 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.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'tcompletelycompatible. So we have to stick to the lowest Common Denominator (C) orusesome component model like COM (it's already supported), CORBA, .NET CLR orJVM. Right, C. Yes I know that. That's why I suggested a C++ to C converter. -Craig
Dec 23 2006
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? -CraigI 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
Dec 23 2006
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ó:C++.I've been thinking about how to provide interoperability between D andbutOne idea I had was to compile C++ to C. I've never used such a compilersinceI'm fairly sure that they exist. Thoughts? -CraigI posted this on 2004-05-02, so I don't know if any changes have been madethen: ---- 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 withDMC andhave interoperability right away. -- Carlos Santander Bernal
Dec 23 2006
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
Dec 26 2006