C Function Parameters

xs0 xs0 at xs0.com
Tue Sep 5 03:40:50 PDT 2006


Tyro wrote:
> Could someone please tell me if I'm reading the following correctly
> 
>     int myfunc(MyStruct *ms, void * (*allocF)(size_t s))
> 
> The second parameter above [void * (*allocF)(size_t s)], is a pointer to 
> a function that accepts a size_t parameter and returns a void pointer? 
> If so, I have two questions:
> 
>     1) Why is the function  pointed to being dereferenced? Why 
> [(*allocF)] instead of [(allocF)]?

It's not being dereferenced, the * just means allocF is a pointer (to a 
function). It's in parentheses because it would otherwise get parsed as 
a function returning void** (as opposed to a function _pointer_ 
returning void*), which is illegal as a parameter, afaik.

>     2) Is [void function(size_t s) allocF] a suitable replacement or 
> would it be better to use a delegate?

Depends :) If myfunc is a C function, you have to use a function; if 
it's a D function, it's usually better to use a delegate..


xs0



More information about the Digitalmars-d-learn mailing list