我怎样才能的typedef函数指针把它自己类型的函数作为参数? [英] How can I typedef a function pointer that takes a function of its own type as an argument?
问题描述
示例:取一个函数的函数(带有一个功能(即...)和一个int)和一个int
Example: A function that takes a function (that takes a function (that ...) and an int) and an int.
typedef void(*Func)(void (*)(void (*)(...), int), int);
它爆炸递归其中(...)
。有没有这个不能做,或有另一种语法的根本原因?在我看来,它应该有可能不进行强制转换。我真的想通过一个调度表,但是我能明白这一点,如果我可以只通过这一种类型。
It explodes recursively where (...)
. Is there a fundamental reason this can't be done or is there another syntax? It seems to me it should be possible without a cast. I'm really trying to pass a dispatch-table but I could figure that out if I could just pass this one type.
推荐答案
你可以用函数指针的结构:
You can wrap the function pointer in a struct:
struct fnptr_struct;
typedef void (*fnptr)(struct fnptr_struct *);
struct fnptr_struct {
fnptr fp;
};
我不知道这是否是在铸造的改进。我怀疑它没有结构是不可能的,因为C需要在使用前必须定义类型和有针对的typedef没有不透明的语法。
I'm not sure if this is an improvement on casting. I suspect that it's impossible without the struct because C requires types to be defined before they are used and there's no opaque syntax for typedef.
这篇关于我怎样才能的typedef函数指针把它自己类型的函数作为参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!