gpt4 book ai didi

C - 从 ‘void*’ 到 ‘void (*)()’ 的无效转换

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:03:26 25 4
gpt4 key购买 nike

当我尝试编译我的程序时得到以下信息:

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);
}

我错过了什么?

最佳答案

您有 void *functionvoid* 不是正确类型的函数指针。 void (*)() 是一种函数指针,因此您可能应该更改函数签名:

void init_TCB (TCB_t *tcb, void (*function)(), void *stackP, int stack_size)

关于C - 从 ‘void*’ 到 ‘void (*)()’ 的无效转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52023167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com