Lea*_*nne 4 c warnings function void
我dispatchQueue.c:215: warning: control reaches end of non-void function
从下面的代码中得到警告..
任何人都可以解释原因吗?
void *dispatcher_threadloop(void *arg){
//thread loop of the dispatch thread- pass the tast to one of worker thread
dispatch_queue_thread_t *dThread = arg;
dispatch_queue_t *dQueue;
dQueue = dThread->queue;
if (dQueue->HEAD!=NULL){
for(;;){
printf("test");
sem_wait(&(dQueue->queue_task_semaphore));
dThread->current_task = dQueue->HEAD;
dQueue->HEAD = dQueue->HEAD->next;
dQueue->HEAD->prev = NULL;
sem_post(&(dQueue->queue_task_semaphore));
break;
//TODO
}
}
Run Code Online (Sandbox Code Playgroud)
}
cni*_*tar 14
因为你声明它void *
(不是void
)并且没有返回任何东西.返回NULL
如果你不需要任何返回值.
void *dispatcher_threadloop(void *arg)
Run Code Online (Sandbox Code Playgroud)
好吧,想象一下如果dQueue->HEAD
是NULL
:if
将不会输入,所以你到达应该返回的函数的结尾void*
- 但你不返回任何东西.
尝试在函数底部返回一些合理的值来解决这个问题.或者添加一个断言,声明此代码应该无法访问,例如:
assert( !"Unreachable code hit" );
Run Code Online (Sandbox Code Playgroud)