How to do a function pointer to "malloc" and "free"?
rempas
rempas at tutanota.com
Sun Oct 10 13:10:27 UTC 2021
On Sunday, 10 October 2021 at 11:26:18 UTC, Elmar wrote:
> Hello rempas.
>
> This is the way:
>
> ```d
> import core.stdc.stdlib : malloc, free;
> extern(C) void* function(ulong) mallocPointer = &malloc;
> extern(C) void function(void*) freePointer = &free;
> ```
>
> `function` in the type is already a function pointer. Not
> immediately obvious though: You also must annotate the type
> with `extern(C)` otherwise it will not work.
Thanks, I'm converting a library from C to D so I have to fix all
the other bugs first to see If it's working but probably it will.
Have an amazing day my friend!
More information about the Digitalmars-d-learn
mailing list