H1 2015 - C++ integration

Paolo Invernizzi via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 14 09:37:44 PST 2015


On Saturday, 14 February 2015 at 17:24:51 UTC, Guillaume Chatelet 
wrote:
> 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 ?

I'm also using pragma(mangle) and struct with a fake virtual 
table...

;-(

I think that another problem is that, if you use a class in D 
instead of a struct, it's a mess with C++ functions taking a 
reference:

     D - class vector .....
     C++ - foo(const vector& a) ...
     C++ - foo(const vector* a) ...

How do we specify the right mangling for the reference?
---
/P


More information about the Digitalmars-d mailing list