考虑以下私有函数声明:
static void ParseCore(SI_32 num_param,const t_config_param config_param[CONFIG_PARAM_BUFFER_SIZE]);
static void ParseGnss(SI_32 num_param,const t_config_param config_param[CONFIG_PARAM_BUFFER_SIZE]);
static void ParseEaf(SI_32 num_param,const t_config_param config_param[CONFIG_PARAM_BUFFER_SIZE]);
static void ParsePps(SI_32 num_param,const t_config_param config_param[CONFIG_PARAM_BUFFER_SIZE]);
static void ParseImu(SI_32 num_param,const t_config_param config_param[CONFIG_PARAM_BUFFER_SIZE]);
在同一源文件中另一个函数的定义内,我初始化以下指针:
void (*ParseConfigGeneric)(SI_32, t_config_param*) = NULL;
以下所有作业都会收到邮件标题中指示的警告:
ParseConfigGeneric = &ParseCore;
ParseConfigGeneric = &ParseGnss;
ParseConfigGeneric = &ParseEaf;
ParseConfigGeneric = &ParsePps;
ParseConfigGeneric = &ParseImu;
这里是GCC的输出:
../src/core/time_mgmt.c: In function âParseConfigFileâ:
../src/core/time_mgmt.c:753:32: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
ParseConfigGeneric = &ParseCore;
^
../src/core/time_mgmt.c:757:32: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
ParseConfigGeneric = &ParseGnss;
^
../src/core/time_mgmt.c:761:32: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
ParseConfigGeneric = &ParseEaf;
^
../src/core/time_mgmt.c:765:32: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
ParseConfigGeneric = &ParsePps;
^
../src/core/time_mgmt.c:769:32: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
ParseConfigGeneric = &ParseImu;
不过,代码的确可以编译,而且似乎工作正常。我查找了类似的问题,但问题始终是指针类型不同于原始函数,但在本例中,它们都是
void*
论点是一致的,所以我不知道问题出在哪里。
调用如下(编译器没有抱怨,我检查了每次调用正确的函数):
(*ParseConfigGeneric)(num_param, config_param);