Function names, Lib used from C and D
evilrat
evilrat666 at gmail.com
Tue Oct 22 15:03:21 UTC 2024
On Tuesday, 22 October 2024 at 12:44:22 UTC, Maximilian Naderer
wrote:
> Dear community,
> I want to create a library which is usable from C and D.
> D should be a first class citizen and C because of FFI for
> other languages.
> The lib is compiled with -betterC
>
> Because C does not have namespaces i want to add the prefix of
> the lib like "leogfx" but in D i don't want that because we
> don't need this.
>
>
> extern(C):
>
> private {
> bool pInit() {
> return true;
> }
> }
>
pragma mangle modifies how the symbol name will appear to the
linker.
```d
pragma(mangle, "leogfx_init")
bool pInit() {
...
}
```
additionally IIRC you can even loop it on itself to self modify
it, at least I remember doing something like this to keep its
name consistent on code refactoring.
```d
pragma(mangle, "leogfx_" ~ __traits(identifier, pInit))
bool pInit() {
...
}
```
More information about the Digitalmars-d-learn
mailing list