extern(C++, ns)

Marc Schütz via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 20 08:38:19 PST 2016


On Wednesday, 20 January 2016 at 05:32:08 UTC, Walter Bright 
wrote:
> Actual code examples of the serious problems would be 
> appreciated. All the namespace code examples you posted were 
> bugs that have since been fixed, or were misunderstandings that 
> were explained.

IMO his description was already quite clear, but here you are:

// a.d
module a;

extern(C++, ns) {
     void fooa();
     void bar();
}

// b.d
module b;

extern(C++, ns) {
     void foob();
}
void bar();

// main.d
import a, b;

void main() {
     fooa();     // ok
     foob();     // ok
     bar();      // Error: b.bar at b.d(6) conflicts with a.ns.bar 
at a.d(5)
     // let's try to disambiguate: we want ns.bar
     ns.bar();   // Error: a.ns at a.d(3) conflicts with b.ns at 
b.d(3)
     a.ns.bar(); // works, but requires superfluous `a`, even 
though
                 // `ns` already makes it unambiguous
}


Of course, it's because of how name lookup works in D, and we 
understand that. But it still diminishes the usability of this 
feature considerably, as the above situation is extremely likely 
to run into if you're porting a sufficiently large C++ library.


More information about the Digitalmars-d mailing list