与[问题]相关:How do you pass a function as a parameter in C?
在 C 中是否可以将参数数量可变的函数传递给另一个函数?如果是这样,有人可以指点我一些文件或填写我吗?谢谢。
最佳答案
您不能将(任何类型的)函数作为参数传递,但可以将指针 传递给函数(同样,几乎任何类型的函数)。使用 typedef 通常最简单:
typedef int (*fptr)(char const *, ...); // e.g., match with `printf`
int apply(fptr f, char const *a, int b) {
return f(a, b);
}
关于在 C 中,您能否将具有可变数量参数的函数作为参数传递给另一个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9866953/