D has better way to bind to C++ than to D.

Hipreme msnmancini at hotmail.com
Wed Feb 22 19:26:40 UTC 2023


Given the following situation: I want to use an externally 
defined D symbol in my current library without adding it as a 
dependency.


- I don't want to use an import path to bind to a symbol in D 
because this would complicate even more my build system, we 
already do it from C by doing: `extern(C) void something();`


We already can bind to a C++ symbol within a namespace by doing:
`extern(C++, "some_namespace")`.

The same can't be said for D. We can't pass a module name which 
the function is being resided.


The practical example right now is that I have my own type 
conversion functions, located in `hip.util.conv`.

I wanted to use the symbol as:
```d
extern(D, "hip.util.conv") extern TO to(TO)(FROM);
```


Even in an untemplated format, that would help me: (like passing 
an optional symbol saying it is a template.
```d
extern(D, "hip.util.conv", to) extern string to(int);
```

I know this is not gonna happen right now but this has a lot of 
use cases and it currently underused because one would need to 
actually use a D mangler library.


More information about the Digitalmars-d mailing list