我需要对一个函数指针类型进行typedef的创建,以创建一个指针数组,并声明大量将在数组中结束的函数。但是,我找不到同时执行这两项操作的方法:要么可以获取数组的指针,要么可以声明函数,但不能同时声明两者。
关于如何在没有大量毫无意义的文本的情况下如何使此代码工作的任何想法,还是我坚持为需要声明的每个函数重复整个函数签名?谢谢。
#include <stdio.h>
// declare a fn ptr type named 'myfunc'
typedef void (*myfunc)(int);
//myfunc A,B,C,etc; **doesn't work, because of the (*)
void A(int); // does work, but becomes very tedious
int main() {
myfunc B = A; // actually assigning a large 2D array
A(42);
B(43);
}
void A(int foo) {
printf("%d\n", foo);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句