extern(C++, NS)

Manu via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 30 03:42:55 PST 2015


On 30 November 2015 at 20:12, Kagamin via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Sunday, 29 November 2015 at 04:57:28 UTC, Walter Bright wrote:
>>
>> We considered making them for mangling only, and rejected it as
>> unworkable, because then two identical names in different namespaces could
>> not be distinguished by the D symbol table system.
>
>
> Didn't you show how two identical names can be distinguished with D symbol
> table system:
>
> On Sunday, 29 November 2015 at 18:29:14 UTC, Walter Bright wrote:
>>
>>     file1.NS.X x;
>>     file2.NS.Y y;
>
>
> It also works the same for C bindings: they share (empty) namespace, but
> identical C declarations can be distinguished in D if they are in different
> modules. Maybe it's better to ignore C namespaces and rely on D module
> system instead?
> Though I don't know why one would want to disallow access to a C++
> namespace.

Exactly, the D module system would still be in place. Assuming they
were in defferent modules, then the D module system would keep them
out of conflict naturally, with rules identical to the normal D rules.
I imagined this; C++ namespace is for mangling, D module is for
scoping. That's not how it seems to be, so my intuition was dead
wrong, but my weekend's experience has convinced me it would be better
how I initially intuited. Thing is, we're presenting a C++ API to D,
so we want to present it in D's terms, that is, the API is distributed
among D modules in a way that makes sense to a D user. I don't want to
present the API in C++ terms, and it's not even practical; stuffing
the entire C++ API into a single D module is crazy. In the cases I'm
interested in, the C++ API is possibly larger than the entire D
codebase that's attached to it.

Walter said this: "Stop trying to bash D into behaving like C++!
[...]", which I was kind of offended by, because it couldn't have been
further from my intent. I'm trying to bash C++ into behaving like D,
and the best way to do that would be to say that C++ namespace is for
mangling only, and expect that the dev will distribute the C++ symbols
among D modules in such a way that makes sense to D developers
consuming the API.


More information about the Digitalmars-d mailing list