Function pointers in C: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]

Consider the following private function declarations:

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

Inside the definition of another function within the same source file, I initialize the following pointer:

void (*ParseConfigGeneric)(SI_32, t_config_param*) = NULL;

All of the following assignments get the warning indicated in the post's title:

ParseConfigGeneric = &ParseCore;
ParseConfigGeneric = &ParseGnss;
ParseConfigGeneric = &ParseEaf;
ParseConfigGeneric = &ParsePps;
ParseConfigGeneric = &ParseImu;

And here the output from 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;

The code does compile and seems to work correctly, though. I looked up similar questions, but the problem is always that the pointer type differs from the original function's, but in this case they are all void* and the arguments match, so I can't tell what the problem is.

The call is as follows (no complaints from the compiler and I checked that the correct function gets called every time):

(*ParseConfigGeneric)(num_param, config_param);

Upvotes: 0

Views: 1370

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409196

The type of the second argument differs between the functions, and the function-pointer variable.

In the functions it's a pointer to const, which it isn't in the function-pointer variable.

The type needs to be exactly equal.

Upvotes: 3

Related Questions