extern(C++, ns)

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 7 07:51:20 PST 2016


On 2016-01-07 15:41, Walter Bright wrote:

> I agree we need to do something about that. It doesn't just happen with
> namespaces names, it happens with all C++ symbols. We need a simple and
> more general solution.

I think that for a symbol outside of the a namespace pragma(mangle) is 
enough. It's not _that_ many names that are reserved in D. What I do is 
I declare a symbol with a valid D identifier of the same length at the 
name I actually want. Then I print the mangled name using .mangleof.

Alternatively enhance core.demangle.mangle to handle different linkages 
and namespaces. Although then ones needs to duplicate the signature.

> One possibility is to add a leading _ to such names:
>
>      extern (C++, _delegate)

For namespaces it's a bit more problematic. But it looks like 
extern(C++, ns) creates a symbol in the D code. If that's the case, then 
it should be possible, in theory, to attach pragma(mangle) to that symbol.

pragma(mangle, "delegate") extern(C++, delegate_)
{
     void foo();
}

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list