extern(C++, ns)
Carl Sturtivant via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jan 7 08:53:48 PST 2016
On Thursday, 7 January 2016 at 14:41:41 UTC, Walter Bright wrote:
> 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.
Right now pragma(mangle...) doesn't work with C++ functions in
namespaces! Surely this is something desirable in its own right.
Is there some reason that pragma(mangle,...) cannot be made to
apply to C++ functions in namespaces? This is clearly the right
answer. And it doesn't presume to know what the mangling is being
used for. Which is to say it follows the D philosophy of
providing options for how solutions are constructed without
imposing upon the author, rather than acting in a "we know best"
fashion, presuming to know all the possibilities for use.
More information about the Digitalmars-d
mailing list