Consider:
extern (C) int* with();
where delegate is a C function name. This, of course, fails because 'with' is a D keyword. A solution is:
extern (C) int* with_();
and have the C/C++ name mangler remove any trailing _ from identifiers.
The prefix version, _with, has problems because it would be impossible to have a C identifier named '_traits' or '_gshared'.
Comment #1 by dfj1esp02 — 2016-01-22T08:16:31Z
Another option:
extern (C++) int __symbol__with();
And let C++ mangler recognize and remove the __symbol__ prefix.
Choose your naming convention:
alias with_ = __symbol__with;
alias _with = __symbol__with;
alias _with_ = __symbol__with;
alias With = __symbol__with;
Comment #2 by dlang-bugzilla — 2017-07-08T01:46:14Z
In this particular case, the easiest workaround is to use pragma(mangle), right?
I understand that this is more useful for C++ functions, whose mangling is non-trivial.
Comment #3 by pro.mathias.lang — 2020-02-19T05:26:08Z
For C `pragma(mangle)` is an easy workaround, however for `extern(C++)`, not only is the mangling non-trivial, but it's currently impossible to do for anything templated, since the mangling depend on template parameters which are not available to `pragma(mangle)`.
Comment #4 by tim.dlang — 2024-06-01T14:24:09Z
Using `pragma(mangle)` is also annoying for type names, because every function using the renamed type needs to use the changed mangling. This is for example necessary for `std::function`, because `function` is a keyword in D. It would be nice if you could change the mangled name of a type once and every function using the type gets the changed name automatically. It could look something like this:
```
import core.stdcpp.xutility : StdNamespace;
import std.traits;
extern(C++, (StdNamespace)) extern(C++, class)
pragma(mangle_name, "function") // This type is called function in C++
struct std_function(F)
{
// ...
}
extern(C++) void f(ref const std_function!(FunctionTypeOf!(void function())) callback);
```
Currently every function like `f` using `std_function` would need `pragma(mangle)` and the exact mangling depends on operating system and processor architecture. It is possible to generate the correct mangling using CTFE, but this still needs to be done for every function.
Comment #5 by robert.schadek — 2024-12-13T18:46:39Z