Skip to content
Advertisement

C – invalid conversion from ‘void*’ to ‘void (*)()’

I am getting the following when I try to compile my program:

invalid conversion from ‘void*’ to ‘void (*)()’

initializing argument 2 of ‘void makecontext(ucontext_t*, void (*)(), int, ...)’ [-fpermissive]

invalid conversion from ‘void (*)()’ to ‘void*’ [-fpermissive] init_TCB(tcb,function,stack,STACK_SIZE);
initializing argument 2 of ‘void init_TCB(TCB_t*, void*, void*, int)’ [-fpermissive]
void init_TCB (TCB_t *tcb, void *function, void *stackP, int stack_size)`

These are the lines of code that are causing the errors:

#include <ucontext.h>

typedef struct TCB_t {
   struct TCB_t     *next;
   struct TCB_t     *prev;
   ucontext_t      context;
} TCB_t; 

void init_TCB (TCB_t *tcb, void *function, void *stackP, int stack_size)
{
   memset(tcb, '', sizeof(TCB_t));       
   getcontext(&tcb->context);      
   tcb->context.uc_stack.ss_sp = stackP;
   tcb->context.uc_stack.ss_size = (size_t) stack_size;
   makecontext(&tcb->context, function, 0);
}

What am I missing?

Advertisement

Answer

You have void *function but void* is not a correct type of a function pointer. void (*)() is a type of a function pointer, so probably you should change your function signature:

void init_TCB (TCB_t *tcb, void (*function)(), void *stackP, int stack_size)
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement