extern(C++, ns) is wrong

evilrat evilrat666 at gmail.com
Wed Oct 10 12:22:06 UTC 2018


On Wednesday, 5 September 2018 at 00:35:50 UTC, Manu wrote:
>>
>> That's all you need really, any symbol you add will cause the 
>> error.
>>
>> extern(C++, bliz):
>>
>> created a symbol "bliz", you can't import a package from 
>> "bliz" cause then there's a symbol clash. I thought you 
>> implemented extern(C++) ...
>
> And yes, the example is actually complete. Again, but I'll 
> simplify the filenames:
>
> ns/bar.d
> -------------
> module ns.bar;
> import ns.baz;
> extern(C++, ns):
>
> ns/baz.d
> -------------
> module ns.baz;
> import ns.bar;
> extern(C++, ns):
>
>
>> dmd ns/bar.d ns/baz.d

I just found this little hack for such situations. It seems like 
a combined effect of mixin template and normal mixin that seems 
to work by abusing the creation of temporary module for each 
instantiation.

The obvious downside is mixin/CTFE being memory hungry and 
compilation times increase.

Also not sure what happens when there is name clashes due to 
multiple symbols imported from multiple modules.

Tested with DMD 2.082 -m32mscoff on Windows.

file1.d
```
     mixin template a01() {
      mixin(`
      extern(C++, namespaceone)
      public void fun ();
     `);
     } mixin a01;

     mixin template a02() {
      mixin(`
      extern(C++, namespaceone)
      public void otherfun ();
     `);
     } mixin a02;
     // the rest ....
```

file2.d
```
     mixin template a03() {
      mixin(`
      extern(C++, namespaceone)
      public void yetanotherfun ();
     `);
     } mixin a03;
     // ...
```



More information about the Digitalmars-d mailing list