当我尝试编译程序时,我得到以下信息:
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)`
以下是导致错误的代码行:
#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, '\0', 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);
}
我想念什么?
答案 0 :(得分:3)
您有void *function
,但是void*
不是正确的函数指针类型。 void (*)()
是一种函数指针,因此您可能应该更改函数签名:
void init_TCB (TCB_t *tcb, void (*function)(), void *stackP, int stack_size)