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

rempas rempas at tutanota.com
Sun Oct 10 10:44:15 UTC 2021


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  function(void*)*ppfree = free;
```

If I do that, I'm getting the following error message:

```
Error: function `core.stdc.stdlib.malloc(ulong size)` is not 
callable using argument types `()`
```

I'm also trying to do the same using "pureMalloc" and "pureFree" 
instead but this time I'm getting the following error:

```
cannot implicitly convert expression `pureMalloc()(size_t size)` 
of type `void` to `extern (C) void* function(ulong)*`
```

Any ideas?


More information about the Digitalmars-d-learn mailing list