www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - interface for C++

reply "Tu Nam" <dreamweaver mail15.com> writes:
I just hope D has an interface for C++ . At now D can access C function
directly but whether in the future will it has any interface to allow C/C++
access D just like Java JNI ?
Jul 26 2004
next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Tu Nam wrote:

 I just hope D has an interface for C++ . At now D can access C function
 directly but whether in the future will it has any interface to allow C/C++
 access D just like Java JNI ?
extern(C) isn't just useful for interfacing C functions. It's also useful for writing D functions that'll be interfaced in C. Obviously you wouldn't be able to (at least easily) give C(++) access to class/struct methods. As has been said already: "Features to Drop" "Link compatibility with C++. The C++ runtime object model is just too complicated - properly supporting it would essentially imply making D a full C++ compiler too." You might be able to hold D object references on the C(++) side, but I haven't tried it. But if you're going to hold anything that was allocated on the D side, don't forget to read http://www.digitalmars.com/d/garbage.html Interfacing Garbage Collected Objects With Foreign Code And remember to initialise the D runtime system, if main is on the C(++) side. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Jul 26 2004
prev sibling parent reply Berin Loritsch <bloritsch d-haven.org> writes:
Tu Nam wrote:
 I just hope D has an interface for C++ . At now D can access C function
 directly but whether in the future will it has any interface to allow C/C++
 access D just like Java JNI ?
For the record, JNI provides a mapping to C from Java. It is up to the implementor to work with the C methods and map it to the C++ code behind it. IOW, it is tantamount to defining the following: extern(C) { // ... } and in the implementation of the C style function calls, using C++. In order to do a more direct extern(C++) one has to take into consideration name mangling. It wouldn't be a direct C++ interface. Instead it might be a set of externs (if done at all): extern(gnuCPP) { } extern(visualCPP) { } etc. There can be a C++ name mangling policy for just about every compiler out there. This is what makes the mapping difficult. Some compilers like the IBM compiler can emulate the name mangling policy of GCC or Microsoft Visual C++. Between that and the popularity of GCC and VC++ makes these the two most popular incompatible binary formats available. However both compile valid C++ (mostly anyway).
Jul 26 2004
parent reply Jason Mills <jmills cs.mun.ca> writes:
Interfacing to C++ would be a killer feature. For me it would mean I 
could immediately start using D in "real world" (i.e. at work) 
application development because I could leverage the mammoth amount of 
existing C++ libraries that I use everyday. Otherwise I must wait until 
D has a set of libraries that covers all the essentials (e.g. GUI, 
Sockets, something like C++ STL ...). Even then it maybe hard to 
convince others I work with to use D because we would have to rewrite 
the libraries we currently use: not likely to happen.

Jason
Jul 26 2004
parent J.P.Fletcher aston.ac.uk writes:
In article <ce3d2m$18so$1 digitaldaemon.com>, Jason Mills says...
Interfacing to C++ would be a killer feature. For me it would mean I 
could immediately start using D in "real world" (i.e. at work) 
application development because I could leverage the mammoth amount of 
existing C++ libraries that I use everyday. Otherwise I must wait until 
D has a set of libraries that covers all the essentials (e.g. GUI, 
Sockets, something like C++ STL ...). Even then it maybe hard to 
convince others I work with to use D because we would have to rewrite 
the libraries we currently use: not likely to happen.

Jason
I have been looking into this using SWIG. I have put some details onto the Wiki4D http://www.prowiki.org/wiki4d/wiki.cgi?DwithSwig John Fletcher
Jul 26 2004