是否有替代语法的typedef函数指针? [英] Is there an alternate syntax to typedef function pointers?
问题描述
有关做一个typedef的函数指针,我们做这样的事情,
的typedef INT(* FUNC)(字符*);
typedef结构{
字符*名称;
FUNC F1;
}
与此相反,我碰到一个code,我不明白。
的typedef INT rl_icpfunc_t(字符*);
typedef结构{
字符*名称; / *功能的用户可打印的名称。 * /
rl_icpfunc_t * FUNC; / *函数调用来完成这项工作。 * /
字符*文档; / *此功能的文档。 * /
}命令;
这是从libedit库中的一个例子code片段。有人可以解释这样对我?
的typedef INT rl_icpfunc_t(字符*);
是定义一个函数原型类型。
rl_icpfunc_t * FUNC;
定义 FUNC
来是指向了前者。
这是相对于直接通过定义一个函数指针类型:
的typedef INT(* prl_icpfunc_t)(字符*);
prl_icpfunc_t FUNC;
这两个approches的结果是一样的:一个指针 FUNC
,指向一个函数返回 INT
,并采取一个参数,就是的char *
。
For doing a typedef for a function pointer, we do something like this,
typedef int (*func) (char*);
typedef struct{
char * name;
func f1;
}
As opposed to this, I came across a code, which I don't understand.
typedef int rl_icpfunc_t (char *);
typedef struct {
char *name; /* User printable name of the function. */
rl_icpfunc_t *func; /* Function to call to do the job. */
char *doc; /* Documentation for this function. */
}COMMAND;
This is a code snippet from an example of the libedit library. Can someone please explain this to me?
typedef int rl_icpfunc_t (char *);
is defining a function prototype as type.
rl_icpfunc_t * func;
defines func
to be a pointer to the former.
This is as opposed to defining a function pointer type directly via:
typedef int (*prl_icpfunc_t) (char *);
prl_icpfunc_t func;
The result of both approches is the same: A pointer func
, pointing to a function returning int
and taking one argument, that is a char*
.
这篇关于是否有替代语法的typedef函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!