Re: How to do a function pointer to "malloc" and "free"?

2021-10-17 Thread Adam Ruppe via Digitalmars-d-learn
On Sunday, 17 October 2021 at 23:07:15 UTC, Elmar wrote: Do you have a link for more information how to initialize the D runtime? Export a function that calls this: http://druntime.dpldocs.info/core.runtime.Runtime.initialize.html And also export a function that calls this:

Re: How to do a function pointer to "malloc" and "free"?

2021-10-17 Thread Elmar via Digitalmars-d-learn
On Sunday, 10 October 2021 at 17:14:30 UTC, Adam Ruppe wrote: On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote: The language subset "BetterC" is required for calling D functions from C though. This is false. You can use any D features when calling it from C, you just need to provide

Re: How to do a function pointer to "malloc" and "free"?

2021-10-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/10/21 6:44 AM, rempas wrote: I'm having the following C code: ``` static void* (*ppmalloc)(size_t) = malloc; static void (*ppfree)(void*) = free; ``` I want to covert this code in D so I try to do the following: ``` static void* function(size_t)*ppmalloc = malloc; static void 

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 14:00:37 UTC, Elmar wrote: On Sunday, 10 October 2021 at 13:56:06 UTC, rempas wrote: Actually I know about BetterC and how to call C functions from D and visa versa. I would also disagree that "BetterC" is almost no improvement over C as about 90% of the

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread Adam Ruppe via Digitalmars-d-learn
On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote: The language subset "BetterC" is required for calling D functions from C though. This is false. You can use any D features when calling it from C, you just need to provide an init and term function that is called from C that runtime

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread Elmar via Digitalmars-d-learn
On Sunday, 10 October 2021 at 13:56:06 UTC, rempas wrote: Actually I know about BetterC and how to call C functions from D and visa versa. I would also disagree that "BetterC" is almost no improvement over C as about 90% of the language is there!! C++ classes are also supported Nice :-) ,

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread Elmar via Digitalmars-d-learn
On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote: 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

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote: Hopefully it will :-) . D has some good C support. You can call any C function from `D` by declaring it `extern(C) `. The language subset "BetterC" is required for calling D functions from C though. Unfortunately, the runtime

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread Elmar via Digitalmars-d-learn
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

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread rempas via Digitalmars-d-learn
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 = extern(C) void function(void*) freePointer = ``` `function` in the type is already a function pointer. Not

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread Elmar via Digitalmars-d-learn
On Sunday, 10 October 2021 at 10:44:15 UTC, rempas wrote: I'm having the following C code: ``` static void* (*ppmalloc)(size_t) = malloc; static void (*ppfree)(void*) = free; ``` I want to covert this code in D so I try to do the following: ``` static void* function(size_t)*ppmalloc = malloc;