www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - C++ Interop Ideas

reply "Craig Black" <cblack ara.com> writes:
The latest D is a big first step in C++ interop.  I wanted to start a thread 
to discuss the technical roadblocks and possibilities regarding the D/C++ 
interface.

I would like to first say that I do not think it is necessary to have 100% 
C++ compatibility.  Instead, I believe it is sufficient to provide 
conventions that can be observed that allow both languages to play nicely 
together.

My understanding of the current C++ interface is that we have 
interoperability via virtual functions only.  We can not link D with C++ 
using non-virtual functions.  My first question is, what are the 
incompatibilities that disallow linking C++ to D with regard to non-virtual 
functions?  I know that we can do so using a C wrapper, but it would be nice 
if native C++ could do this as well, even if only primitive types are 
allowed as parameters.

My idea is to provide more interoperability using an interop library.  For 
example, it may be futile to try to make STL vector compatible with D 
arrays.  However, perhaps there is a C++ templated array class that could be 
made compatible somehow with D arrays or a D templated array class.  With 
the library approach, the idea is not to create a 100% interop solution. 
Instead, it is to provide conventions that must be followed in order to make 
interoperability possible..

My next question is what incompatibilities exist that prohibit C++ classes 
from interoperating with D classes?  I know inheriting from object is one of 
them.  Would it be possible to create a C++ object class that could be 
inherited to facilitate D interoperability?

If anyone else has any ideas or input it is welcome.

-Craig 
Oct 15 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Craig Black" <cblack ara.com> wrote in message 
news:fevgtk$bma$1 digitalmars.com...

 My understanding of the current C++ interface is that we have 
 interoperability via virtual functions only.  We can not link D with C++ 
 using non-virtual functions.  My first question is, what are the 
 incompatibilities that disallow linking C++ to D with regard to 
 non-virtual functions?  I know that we can do so using a C wrapper, but it 
 would be nice if native C++ could do this as well, even if only primitive 
 types are allowed as parameters.

The first section in the "Interfacing to C++" part of the spec is called "Calling C++ Global Functions From D", and the second "Calling Global D Functions From C++". Hopefully you've seen this section of the spec?
Oct 15 2007
parent "Craig Black" <cblack ara.com> writes:
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message 
news:fevr78$td1$1 digitalmars.com...
 "Craig Black" <cblack ara.com> wrote in message 
 news:fevgtk$bma$1 digitalmars.com...

 My understanding of the current C++ interface is that we have 
 interoperability via virtual functions only.  We can not link D with C++ 
 using non-virtual functions.  My first question is, what are the 
 incompatibilities that disallow linking C++ to D with regard to 
 non-virtual functions?  I know that we can do so using a C wrapper, but 
 it would be nice if native C++ could do this as well, even if only 
 primitive types are allowed as parameters.

The first section in the "Interfacing to C++" part of the spec is called "Calling C++ Global Functions From D", and the second "Calling Global D Functions From C++". Hopefully you've seen this section of the spec?

Guess I skimmed over it too fast. Thanks.
Oct 15 2007