mangling of extern(C) members

evilrat evilrat666 at gmail.com
Fri Jan 11 07:27:56 PST 2013


On Friday, 11 January 2013 at 15:19:23 UTC, Adam D. Ruppe wrote:
> On Friday, 11 January 2013 at 15:00:26 UTC, Daniel Murphy wrote:
>> And this is the only complete way, unless you can guarantee 
>> the C++ calling conventions can be simulated with extern(C)
>
> Guarantees aren't terribly important to me... I'm doing a lot 
> of hacks as it is. Of course if the compiler can make it all 
> just work, that'd be great. I'm convinced there's still more 
> practical low hanging fruit for more C++ interop.
>
>> https://github.com/D-Programming-Language/dmd/pull/1085
>
> Excellent, let's get it merged. I can't imagine it breaking any 
> existing code and giving us this flexibility will let us do 
> more practical hacks.

but for more c++ interop you would need to know:
1) data(struct/class) size to malloc enough space
2) appropriate constructor and arguments(can be parsed and 
matched with existing schemes, only 3 major compiler mangling 
schemes anyway...)
3) placement new(can try to use same schemes to get c++ runtime 
version from mangling matched in 2)
4) use asm statements to pass your new c++ 'this'(from p.1) if 
any to placement new (p.3)
5) call your ctor from p.2
6) only now you have your C++ object constructed within D

the 1) is the biggest problem, only this is already enough to 
block the way down


More information about the Digitalmars-d mailing list