C 警告“返回"没有值,在函数中返回非空 [英] C warning 'return' with no value, in function returning non-void
问题描述
我收到了这个警告.
警告:'return' 没有值,在函数中返回非空值.
warning : 'return' with no value, in function returning non-void.
推荐答案
你有类似的东西:
int function(void)
{
return;
}
添加返回值,或将返回类型更改为 void.
Add a return value, or change the return type to void.
错误信息很清楚:
警告:'return' 没有值,在函数中返回非空值.
warning : 'return' with no value, in function returning non-void.
没有价值的回报与我展示的相似.该消息还告诉您,如果该函数返回void",则不会发出警告.但是因为该函数应该返回一个值,而您的返回"语句却没有,所以您遇到了问题.
A return with no value is similar to what I showed. The message also tells you that if the function returns 'void', it would not give the warning. But because the function is supposed to return a value but your 'return' statement didn't, you have a problem.
这通常表示古代代码.在 C89 标准之前的日子里,编译器不一定支持void".当时接受的风格是:
This is often indicative of ancient code. In the days before the C89 standard, compilers did not necessarily support 'void'. The accepted style was then:
function_not_returning_an_explicit_value(i)
char *i;
{
...
if (...something...)
return;
}
从技术上讲,该函数返回一个 int
,但没有预期的值.这种风格的代码会引发您收到的警告 - C99 正式将其取缔,但出于向后兼容性的原因,编译器继续接受它.
Technically, the function returns an int
, but no value was expected. This style of code elicits the warning you got - and C99 officially outlaws it, but compilers continue to accept it for reasons of backwards compatibility.
这篇关于C 警告“返回"没有值,在函数中返回非空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!