On Friday, 4 April 2014 at 21:39:01 UTC, bearophile wrote:
Tove:

Why would we need new ways of declaring scopes in D? Overriding the external mangling should be sufficient? If there are collisions you can use any type of scope you prefer to avoid the issue, modules, structs, templates, even functions or blocks...

void fun1() { extern (C++, S::T) int foo();}
void fun2() { extern (C++, S::T::U) int foo();}

extern (C++, S::T::U) int foo();
struct test { extern (C++, S::T) int foo();}

This seems promising, but this idea needs to become simpler.

Bye,
bearophile

This seems like it would be simple if it came with a recommended style for library wrappers, e.g.

// C++
namespace A {
  namespace B {
    void f1();
    void f2();
  }
  namespace C {
    void f3();
    void f4();
  }
}

// D
struct A {
  struct B {
  extern(C++, A, B):
    static void f1();
    static void f2();
  }
  struct C {
  extern(C++, A, C):
    static void f3();
    static void f4();
  }
}

This can be easily generated by hand or with something like SWIG, and keeps the semantics of "extern" consistent throughout the language (it still only affects the ABI). This also keeps things simple for users who just want to call one function.

// D
void callF1() {
  extern(C++, A, B) void f1();
  f1();
}

I used "," instead of "::" because it avoids adding a new token, but that's more of an aesthetic issue.

Reply via email to