C++ to D

Elie Morisse via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 3 16:13:04 PDT 2015


On Tuesday, 31 March 2015 at 20:37:37 UTC, Jeff Jones wrote:
> Is it possible to modify either a C++ compiler or in code to 
> make classes more D ish? e.g., instead of just the 
> vtable(which, IIRC is slightly different between the two) add 
> the metadata pointer and whatever else?
>
> What I'm getting at, is there a somewhat simple way(not 
> creating a new C++ but either through macros, small compiler 
> changes, or whatever) to make C++ objects D compatible instead 
> of the other way?
>
> I.e., we can't take anything away from D classes since we will 
> break D. But we should be able to add to C++ classes without 
> breaking C++. If we can add the info that D needs then both 
> should get along happily? I'm mainly talking about a simple 
> code based solution but I'm also curious about how easily this 
> would be by compiler modification.

You can't make the layout of C++ classes inheriting from multiple 
bases match D's class layouts because D's multiple inheritance is 
more limited.

Also a big downside is that "D-flavored ABI" C++ binaries 
couldn't interact easily with "normal ABI" C++ binaries because 
even if the modified C++ compiler is explicitly told which 
library/set of headers is normal and which isn't, the usage of 
any class from the normal C++ libs by D-flavored ones will form a 
mixture of both ABI so not usable by D, and it's not helping that 
some classes can be codegen'd into several libs.
So every C++ lib would need to be recompiled to avoid the 
ramifications of interacting with both ABI?

 From my time poking around Clang's code it just seems easier and 
more convenient to reimplement C++ multiple inheritance and 
downcasts in DMD.


More information about the Digitalmars-d mailing list