开发者

Quick question: explain this typedef

开发者 https://www.devze.com 2022-12-25 13:58 出处:网络
typedef开发者_如何学C int py_var_t (void *); it is used as: py_var_t *somesymbol It defines py_var_t to be the type of a function returning int and taking a void* pointer as argument.This:
typedef开发者_如何学C int py_var_t (void *);

it is used as:

py_var_t *somesymbol


It defines py_var_t to be the type of a function returning int and taking a void* pointer as argument.


This:

typedef int py_var_t (void *);

defines the type of the function as described by @milan1612. Then this:

py_var_t *somesymbol;

creates a pointer to such a function. You could also have created the pointer like this:

int (*somesymbol)(void *);

but use of typedefs is better practice, particularly when the function types get more complicated.

0

精彩评论

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

关注公众号