extern(C++, ns)

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 3 00:10:21 PST 2016


On 1/2/2016 10:56 PM, Manu via Digitalmars-d wrote:
> I don't want that. That's what modules are for.

C++ namespaces are not modules, either in C++ or D. We investigated making them 
'special' modules, and discarded that as unworkable.


> Given a C++ symbol 'NS::CSymbol', the D symbol 'x.y.NS.CSymbol' bears no
> meaningful relation. D still prefixes the module scope.

D will not prefix the module name to the mangled C++ namespace name.

> The user will almost certainly instead do:
>
> module NS; // a module for the C++ thing
> extern(C++, NS) void func();
>
> Which would give them the symbol 'NS.NS.func'.

That's correct, although I would not recommend that practice. Note that you can 
use alias to 'lift' a scope into the current scope.

> Surely what they intended was 'NS.func' to match the C++ symbol?

Then you'd need a global namespace, which D does not have.


>     I am not aware of any forward reference issues with C++ namespaces, so
>     without an example, I cannot do anything.
> https://issues.dlang.org/show_bug.cgi?id=15389

Thank you.



More information about the Digitalmars-d mailing list