www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Idea: Extern C++ Classes

reply "Craig Black" <craigblack2 cox.net> writes:
The C++ compatibility provided in D 2.0 is a huge step forward.  However, if 
my understanding is correct, the biggest limitation with it is that D's 
classes are not ABI compatible with C++ classes.  This means that non-static 
member functions can't be called between D and C++.

To remedy this issue, I propose that we allow extern C++ declarations on 
classes.  This would mean that the class behaves like a C++ class (doesn't 
inherit Object, no GC by default, only polymorphic if it contains virtual 
functions, etc.)

I realize this may require a moderate amount of Walter's time.  I therefore 
would propose this as perhaps a D 3.0 feature.

What issues would arise that I am forgetting to address?  Does anyone have a 
better solution for this?

-Craig 
Mar 31 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Craig Black wrote:
 The C++ compatibility provided in D 2.0 is a huge step forward.  
 However, if my understanding is correct, the biggest limitation with it 
 is that D's classes are not ABI compatible with C++ classes.  This means 
 that non-static member functions can't be called between D and C++.
 
 To remedy this issue, I propose that we allow extern C++ declarations on 
 classes.  This would mean that the class behaves like a C++ class 
 (doesn't inherit Object, no GC by default, only polymorphic if it 
 contains virtual functions, etc.)
 
 I realize this may require a moderate amount of Walter's time.  I 
 therefore would propose this as perhaps a D 3.0 feature.
 
 What issues would arise that I am forgetting to address?  Does anyone 
 have a better solution for this?
You can already call C++ member functions declared with extern(C++). The problems, however, stem from C++ constructors, destructors, and special functions.
Mar 31 2008
parent "Craig Black" <craigblack2 cox.net> writes:
"Walter Bright" <newshound1 digitalmars.com> wrote in message 
news:fssh36$8sl$1 digitalmars.com...
 Craig Black wrote:
 The C++ compatibility provided in D 2.0 is a huge step forward.  However, 
 if my understanding is correct, the biggest limitation with it is that 
 D's classes are not ABI compatible with C++ classes.  This means that 
 non-static member functions can't be called between D and C++.

 To remedy this issue, I propose that we allow extern C++ declarations on 
 classes.  This would mean that the class behaves like a C++ class 
 (doesn't inherit Object, no GC by default, only polymorphic if it 
 contains virtual functions, etc.)

 I realize this may require a moderate amount of Walter's time.  I 
 therefore would propose this as perhaps a D 3.0 feature.

 What issues would arise that I am forgetting to address?  Does anyone 
 have a better solution for this?
You can already call C++ member functions declared with extern(C++). The problems, however, stem from C++ constructors, destructors, and special functions.
But that only works for virtual functions declared using interfaces, right? That is somewhat limiting. It would be nice to take it a step further. -Craig
Apr 01 2008