c语言定义兼容多类型指针,C中的函数指针:警告:来自不兼容指针类型的赋值[-WinCompatible指针类型]...

考虑以下私有函数声明:

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值