extern(C++, ns)

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 7 06:41:41 PST 2016


On 1/7/2016 6:03 AM, Marc Schütz wrote:
> But there remains the issue of using D keywords in C++ namespaces. Maybe there
> could be a variant `extern(C++, "ns1.ns2.as.string")`, that doesn't create
> symbols and affects mangling only?

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.

One possibility is to add a leading _ to such names:

     extern (C++, _delegate)

The leading _ means 'strip the leading _ when mangling for C++'. If you need a 
leading _ in the C++ name, use two __ in the D name. And so on. This may break 
existing code. Perhaps the _ stripping can only happen when the stripped 
identifier is not a D keyword, that won't break anything.

I know it's hackish, but it's awfully simple and straightforward. An analogous 
scheme is used in Ddoc, so there's precedent.


More information about the Digitalmars-d mailing list