我的程序中包含以下文件,带有某些函数定义的头,以及带有函数主体的程序。
something.h
typedef struct _foo {
int id;
int lucky_number;
} foo;
typedef void (*pointer_fc)(foo *);
void first(foo *);
void second(foo *);
void third(foo *);
extern pointer_fc fc_bases[3];
something.c
pointer_fc fc_bases[] = {first, second, third};
/* body of functions */
请注意,在标头中,我定义了一个指向函数的指针数组,在something.c
程序中,函数与该数组的每个元素相关联。
假设在某个时刻我需要在main.c
程序中调用所有3个函数。 这样,我如何使用指针的extern数组在main.c
调用此函数。