H1 2015 - C++ integration

Guillaume Chatelet via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 14 09:24:50 PST 2015


I did a few tests. Using a class doesn't work because of the 
added vptr.
The data would be managed at the same time on the D and the C++ 
side.

Structs work however because we can add something like this :

struct std_string {
   void[8] _ = void; // to match sizeof(std::string) and pad the 
object correctly.
}

The padding will be left untouched on the D side because of void 
initializer and will be managed entirely on the C++ side.

Using a class crashes (C++ and D step on each others toes).

Structs work expect for :
- name mangling on linux (bug reported in my first message)
- name mangling on Windows at least (name would be mangled as a 
struct instead of class)
- disabled default constructor.

Mangling on Linux is fixable as well as default construction : we 
can provide a special function that would create a new instance.

But for the windows name mangling, I don't see a way out in the 
language as it is right now.

Any ideas ?


More information about the Digitalmars-d mailing list