功能回到本身 [英] Function Returning Itself
问题描述
是否有可能宣布一些函数类型 func_t
它返回一个类型, func_t
?
在换句话说,有可能是一个函数返回自己?
// func_t被声明为某种函数指针
func_t富(无效* ARG)
{
返回&安培; foo的;
}
或者,我将不得不使用无效*
和类型转换?
没有,你不能宣布在C.递归函数类型除结构(或联合)内,它不可能在C <声明递归式/ p>
现在的无效*
解决方案,无效*
只保证持有对象的指针,而不是指向功能。能够转换函数指针和无效*
仅作为一个扩展。
Is it possible to declare some function type func_t
which returns that type, func_t
?
In other words, is it possible for a function to return itself?
// func_t is declared as some sort of function pointer
func_t foo(void *arg)
{
return &foo;
}
Or would I have to use void *
and typecasting?
No, you cannot declare recursive function types in C. Except inside a structure (or an union), it's not possible to declare a recursive type in C.
Now for the void *
solution, void *
is only guaranteed to hold pointers to objects and not pointers to functions. Being able to convert function pointers and void *
is available only as an extension.
这篇关于功能回到本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!