开发者

function pointers query

what is the difference between these two below:

typedef void (*my_destructor)(void *);

typedef void (*my_destructor)(v开发者_如何学Gooid *)  my_func_ptr;

is the second one valid?


The first one declares a type called my_destructor. This type is a pointer to a function taking a parameter of type void* and returning nothing.

The second one is not valid, what are you trying to do ? If you want to declare a variable of type my_destructor, you have to do this:

typedef void (*my_destructor)(void *);
my_destructor my_func_ptr;


You are declaring a type for a pointer function. The first one is the good one it mean you have a type named my_destructor who is a pointer to a function (*my_destructor) that take a void pointer (void *) on arguments and who return nothing (void).

Now you can use your type as if it was another type like for example char, long or whatever.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜