警告:控制到达非 void 函数的末尾
我有一个名为 Now 的函数,
void *func(void *arg)
{
///does some operation
}
尽管我将返回类型声明为 void *
,但我收到编译器警告“控制到达非 void 函数的末尾”。
谁能告诉我如何解决这个警告?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
返回类型是
void *
,这意味着您将返回一个指针。也许您想输入void
,这意味着您不会返回任何内容?The return type is
void *
, that means that you will return a pointer. Perhaps you wanted to typevoid
, which means that you will not return anything?我们需要所有代码才能真正了解发生了什么,但编译器无法从该代码中判断该函数是否会到达末尾并仍然返回某些内容。你说它会返回一个指针——一个
void*
——但什么也没返回。这不是一个 void 函数,而是一个void*
函数。编译器期望您返回一个void*
,但您只是从函数末尾掉了下来。您还可能有一个无限
while
循环,编译器足够聪明,知道该函数不会返回,但这纯粹是猜测,因为您没有发布所有代码。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 avoid*
function. The compiler is expecting you to return avoid*
, 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.