extern(C++, ns)

Martin DraĊĦar via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 13 01:11:43 PST 2016


Dne 13.1.2016 v 7:51 Walter Bright via Digitalmars-d napsal(a):
> If you like:
> 
>     extern (C++) {
>         int a;
>         extern (C++,ns) {
>             int a;
>         }
>     }
> 
> The whole point of scoped names is to be able to do this.
> 
> Also, I would expect to be able to access "ns.a" with the syntax "ns.a",
> meaning ns has to be a scope.

The question is, how often would you want to do that in a real-world
scenarios? By catering for this particular use-case, things got
needlessly more complicated. It is quite strange that you consider using
D's module system as awkward, yet you have no problem with all the
convoluted solutions to Manu's problem.

The scoping introduces only a poor man's analogy to C++ namespaces. As
was pointed out by others, the same namespace tends to reside in many
C++ files and if you attempt to mimic that file structure in D, you will
have to disambiguate. Which leaves you with a weird combination of
module system and namespaces.

Your solution with Rainer's example on map and vector is to _not_ use
the namespace at all, which is in conflict with your statement that you
'would expect to be able to access "ns.a" with the syntax "ns.a"'.

>> Of course, it would save a lot of effort if you agreed that the design
> is wrong, and none of us need to do anything further.
> 
> I regard it as crucial to determine the cause of your problems before
> assuming it is the design.

I am with Manu on this one. Introducing scoping to C++ namespaces is a
design mistake, because it fails to deliver on its promise to emulate
true C++ namespaces. Namespaces in extern declaration should only affect
linking and leave everything else to D's module system.

Martin




More information about the Digitalmars-d mailing list