maddy
maddy

Reputation: 47

warning: control reaches end of non-void function

I have a function named

void *func(void *arg)
{
    ///does some operation
}

Now I am getting a compiler warning that "control reaches end of non-void function" even though i declare the return type as void *.

Can anyone please tell me how to fix up this warning?

Upvotes: 0

Views: 7092

Answers (2)

user195488
user195488

Reputation:

We need all the code to truly see what is going on, but he compiler cannot tell from that code if the function will ever reach the end and still return something. You said it would return a pointer -- a void* -- and returned nothing. That isn't a void function, that is a void* function. The compiler is expecting you to return a void*, but instead you just fall off the end of the function.

You may also have an infinite while loop, which the compiler is smart enough to know that the function will not return, but this is pure speculation because you did not post all the code.

Upvotes: 0

Andrea Bergia
Andrea Bergia

Reputation: 5552

The return type is void *, that means that you will return a pointer. Perhaps you wanted to type void, which means that you will not return anything?

Upvotes: 3

Related Questions