C++ Interop Ideas

Craig Black cblack at ara.com
Mon Oct 15 03:56:56 PDT 2007


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 





More information about the Digitalmars-d mailing list