Is there any good reason why C++ namespaces are "closed" in D?

CommanderZot no at no.no
Mon Jul 30 13:17:59 UTC 2018


On Monday, 30 July 2018 at 12:07:31 UTC, Daniel N wrote:
> On Monday, 30 July 2018 at 08:44:14 UTC, Walter Bright wrote:
>>
>>   struct S1 { extern(C++, ns) void foo(); } alias foo = 
>> S1.ns.foo;
>>   struct S2 { extern(C++, ns) void bar(); } alias bar = 
>> S2.ns.bar;
>>
>> Perfect!
>>
>>
>
> I tried that but it mangles wrong.. it includes "S1" which is 
> not what you want, so I gave up binding to C++ and used C 
> instead.
>
> pragma(msg, foo.mangleof);
> _ZN2S12ns3fooEv
>
> Even if it worked, you'd still see the full name in error 
> messages and reflection.
>
> It's much harder to undo parts of one complex operation, 
> compared to composing two simple building blocks. Couldn't we 
> just add a new parameter to control scope or add a pragma or 
> something?

there also is an issue when using extern(C) in mixins. see 
https://issues.dlang.org/show_bug.cgi?id=12575



More information about the Digitalmars-d mailing list