How to do a function pointer to "malloc" and "free"?
chrehme at gmx.de
Sun Oct 10 13:52:57 UTC 2021
On Sunday, 10 October 2021 at 13:10:27 UTC, rempas wrote:
> 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!
Hopefully it will :-) .
D has some good C support. You can call any C function from `D`
by declaring it `extern(C) <function-signature>`.
The language subset "BetterC" is required for calling D functions
from C though. Unfortunately, the runtime features of BetterC are
limited and some of C's language features aren't availabe like
C99 variable-length-arrays. "BetterC" is like programming in C
with little more comfort but phobos is unusable which makes
BetterC almost no improvement over C. BetterC helper librarys
like Tanya or Tango do exist.
In that case it can indeed be better for you to convert the
program's entry point into D code. This is unfortunate because it
prevents C code bases from using D.
There is a tool [C++ Conversion
Wizard](https://rainers.github.io/visuald/visuald/CppConversion.html) which could be able to convert C++ and C to D but I don't know how good it is and whether it's usable for free on a GNU/Linux derivative OS. It's only half-automatic.
More information about the Digitalmars-d-learn