DIP61: redone to do extern(C++,N) syntax

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 28 13:50:45 PDT 2014


On 4/28/2014 7:27 AM, Steven Schveighoffer wrote:
> Consider this code:
>
> module foo;
>
> void func() {}
>
> module bar;
>
> extern(C) func();
>
> module prog;
>
> import foo;
> import bar;
>
> void main()
> {
>     func(); // error
>     foo.func(); // ok
>     bar.func(); // ok, uses C binding (no name mangling)
> }
>
> In this case, even though the C function is not mangled or in any other
> namespace, the module can be used for unambiguous calling.

Right.


> module foo;
>
> void func() {}
>
> module bar;
>
> extern(C++, foo) void func(); // foo::func in C++ land
>
> module prog;
>
> import foo;
> import bar;
>
> void main()
> {
>     func(); // error
>     foo.func(); // ALSO error

No, not an error. Why would it be?

>     bar.func(); // Not error, BUT it's actually calling foo::func from C++ land!

That's right. Note that foo::func() is not the same as bar.foo.func().

> }



More information about the Digitalmars-d mailing list