Hello
I would like to initialize an arry containing function pointers with adresses of functions that have a variable number of arguments.
Below the code that works in principle. I would however get rid of the warning message during compilation pointing to the initialzation of the funtion pointers in the array. How do I need to cast the pointers to the functions ?
Code:
gcc func_ptr_init.c
func_ptr_init.c:28: warning: initialization from incompatible pointer type
func_ptr_init.c:32: warning: initialization from incompatible pointer type
Code:
#include<stdio.h>
unsigned char func1_ptr(unsigned int* if_desc, int* result_code)
{
*if_desc = 1;
*result_code = 1;
return(0);
}
unsigned char func2_ptr(unsigned int* if_desc, int* result_code)
{
*if_desc = 2;
*result_code = 2;
return(0);
}
struct _server_command_table_t
{
char* command_string;
unsigned char (*callback_func)(unsigned int* if_desc, ...);
};
struct _server_command_table_t table[] =
{
{
"String1",
&func1_ptr
},
{
"String2",
&func2_ptr
}
};
int main(int argc,char **argv)
{
int interface;
int result;
printf("%s\n",table[0].command_string);
printf("%d\n",table[0].callback_func(&interface,&result));
printf("interface=%d, result=%d\n",interface,result);
return(0);
};
Thanks
Tilman