I'm having getting the above warning and understand it, but just don't know how to fix it. My code is below, but basically what I'm doing is storing a function pointer in a struct, and initializing the struct in another function that I call from my main. The code seems to compile when I use it with a default function (i.e. free()) but not when I use it with the test_func function below. Thoughts?
Struct:
typedef struct my_struct {
my_type **double_pointed;
int num;
void (*funcp)(void *data);
} my_struct_t;
Init function:
my_struct_t *init(int num, void (*my_funcp)(void *data)) {
// unimportant code to the problem, but basically just some mallocs for the other data
my_struct_t *my_str;
my_str->funcp = my_funcp;
return struct;
}
function I want to point to:
void desired_func(my_type *obj) {}
my call to the init func:
init(5, desired_func);
full error:
incompatible pointer types assigning to 'void (*)(void *)' from 'void (my_type *)'
on the line in the init function above:
my_struct_t *my_str;
my_str->funcp = my_funcp;