c,控制到达c中非void函数的末尾
我有以下代码中的 dispatchQueue.c:215: warning: controlreached 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
}
}
}
I have dispatchQueue.c:215: warning: control reaches end of non-void function
warning from the code below..
Can anyone please explain why?
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
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
因为您声明它
void *
(不是void
)并且不返回任何内容。如果不需要任何返回值,则返回NULL
。Because you are declaring it
void *
(notvoid
) and not returning anything. ReturnNULL
if you don’t need any return value.好吧,想象一下如果
dQueue->HEAD
为NULL
会发生什么:if
不会被输入,所以你会到达结尾该函数应该返回一个void*
- 但你不返回任何东西。尝试在函数底部返回一些合理的值来解决此问题。或者添加一个断言,声明此代码应该无法访问,例如:
Well, imagine what happens if
dQueue->HEAD
isNULL
: theif
won't be entered, so you get to the end of the function which is supposed to return avoid*
- but you don't return anything.Try returning some sensible value at the bottom of your function to fix this. Or add an assertion which states that this code should be unreachable, like:
函数的签名表明它返回一个
void *
,它是一个指针,与void
不同。如果您的函数不返回任何内容,请使用
void
。The signature for your function indicates it returns a
void *
, which is a pointer and is different thanvoid
.If your function isn't meant to return anything, use
void
.这是一个老问题,但如果有人试图解决这个问题(对于 pthreads),您可能需要返回:
pthread_exit(void *retval)
(对于可连接线程)pthread_exit(NULL)
(对于分离线程)This is an old question, but if someone's trying to figure this out (for pthreads), you MAY want to return:
pthread_exit(void *retval)
(For joinable threads)pthread_exit(NULL)
(For detached threads)http://publib.boulder.ibm.com/infocenter/tpfhelp/current/topic/com.ibm.ztpf-ztpfdf.doc_put.cur/gtpm1/m1rhnvf.html
从原型来看,你似乎想返回一些东西。
http://publib.boulder.ibm.com/infocenter/tpfhelp/current/topic/com.ibm.ztpf-ztpfdf.doc_put.cur/gtpm1/m1rhnvf.html
From the prototype it seems you want to return something.