我正在做一个线程库(使用 uncontext.h 更改上下文)。我的函数是 void 类型,我无法返回。但是即使我不返回,编译时也会出现这个警告:
dccthread.c: In function ‘dccthread_init’:
dccthread.c:184:1: warning: ‘noreturn’ function does return [enabled by default]
}
这是函数的简化代码(没有一些细节):
void dccthread_init(void (*func), int param) {
int i=0;
if (gerente==NULL)
gerente = (dccthread_t *) malloc(sizeof(dccthread_t));
getcontext(&gerente->contexto);
gerente->contexto.uc_link = NULL;
gerente->contexto.uc_stack.ss_sp = malloc ( THREAD_STACK_SIZE );
gerente->contexto.uc_stack.ss_size = THREAD_STACK_SIZE;
gerente->contexto.uc_stack.ss_flags = 0;
gerente->tid=-1;
makecontext(&gerente->contexto, gerente_escalonador, 0);
if (principal==NULL)
principal = (dccthread_t *) malloc(sizeof(dccthread_t));
getcontext(&principal->contexto);
principal->contexto.uc_link = NULL;
principal->contexto.uc_stack.ss_sp = malloc ( THREAD_STACK_SIZE );
principal->contexto.uc_stack.ss_size = THREAD_STACK_SIZE;
principal->contexto.uc_stack.ss_flags = 0;
makecontext(&principal->contexto, func, 1, param);
swapcontext(&gerente->contexto, &principal->contexto);
}
请注意,我不会随时返回。但是 gcc 给了我这个警告。有谁知道是什么问题?