DIP61: redone to do extern(C++,N) syntax
Regan Heath via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 30 03:01:31 PDT 2014
On Wed, 30 Apr 2014 10:20:22 +0100, Regan Heath <regan at netmail.co.nz>
wrote:
Something else to think about.
C# has the same problem and has solved it the following way..
[main.cs]
using ..
using CSTest_Test1;
using CSTest_Test2;
namespace CSTest
{
class Program
{
static void Main(string[] args)
{
Test1.GetLastError(); // class, not namespace required to call
method
Test2.GetLastError(); // class, not namespace required to call
method
}
}
}
[Test1.cs]
using ..
namespace CSTest_Test1
{
public static class Test1
{
[DllImport("coredll.dll", SetLastError = true)]
public static extern Int32 GetLastError();
}
}
[Test2.cs]
namespace CSTest_Test2
{
public static class Test2
{
[DllImport("coredll.dll", SetLastError = true)]
public static extern Int32 GetLastError();
}
}
GetLastError() is always going to unambiguous here because it *must* live
inside a C# class and that class name is *always* required in the call to
it.
If D has replaced classes/namespaces with modules, then the answer to our
problem may be to use the C++ namespace *only* to mangle the symbol, and
*only* use the D module for lookup resolution.
module a;
extern(C++, std) class string {..}
module b:
extern(C++, std) class string {..}
extern(C++, std) class vector {..}
module userland;
import a;
import b;
void main()
{
string x = new string(); //error ambiguous (same resolution as for D
symbols)
a.string x = new a.string(); //ok
b.vector y = new b.vector(); //ok
}
Regan
More information about the Digitalmars-d
mailing list