I am practicing to build a struct data structure in C, and the struct has a field pointer to function. I have written up the following code, but when I tried to compile with gcc, I got the following error:
In function ‘main’: custhreadsTest1.c:27:16: warning: assignment from incompatible pointer type [enabled by default]
Whats the correct way of assigning a function pointer to the pointer field in my struct? Thanks a lot!
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
typedef struct
{
ucontext_t (*gt_context);
void (*function)(void *);
int status_flag;
} custhread_t;
void *add(void *)
{
// do something here
}
int main(void)
{
ucontext_t ctx_main;
getcontext(&ctx_main);
custhread_t th1;
th1.gt_context = &ctx_main;
th1.function = &add;
th1.status_flag = 1;
return 0;
}
void*, but the function you're assigning to it takesvoid.void.