Leanne Leanne - 4 years ago 88
C Question

c, control reaches end of non-void function in c

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){
dThread->current_task = dQueue->HEAD;
dQueue->HEAD = dQueue->HEAD->next;
dQueue->HEAD->prev = NULL;


Answer Source

Well, imagine what happens if dQueue->HEAD is NULL: the if won't be entered, so you get to the end of the function which is supposed to return a void* - 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:

assert( !"Unreachable code hit" );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download