10

示例:一个函数接受一个函数(接受一个函数 (that ...) 和一个 int)和一个 int。

typedef void(*Func)(void (*)(void (*)(...), int), int);

它在哪里递归爆炸(...)。是否有根本原因无法做到这一点,或者是否有其他语法?在我看来,没有演员表应该是可能的。我真的在尝试传递一个调度表,但我可以弄清楚我是否可以通过这种类型。

4

2 回答 2

10

您可以将函数指针包装在结构中:

struct fnptr_struct;
typedef void (*fnptr)(struct fnptr_struct *);
struct fnptr_struct {
  fnptr fp;
};

我不确定这是否是对铸造的改进。我怀疑没有结构是不可能的,因为 C 要求在使用类型之前定义类型,并且 typedef 没有不透明的语法。

于 2009-05-03T05:08:44.377 回答
6

直接做是不可能的。您唯一的选择是让函数指针参数接受未指定的参数,或者接受指向包含函数指针的结构的指针,正如Dave 建议的那样。

// Define fnptr as a pointer to a function returning void, and which takes one
// argument of type 'pointer to a function returning void and taking
// an unspecified number of parameters of unspecified types'
typedef void (*fnptr)(void (*)());
于 2009-05-03T05:28:32.723 回答