为什么&QUOT警告;控制到达非void函数&QUOT结束; main函数? [英] Why a warning of "control reaches end of non-void function" for the main function?

查看:243
本文介绍了为什么&QUOT警告;控制到达非void函数&QUOT结束; main函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行下面的C codeS,并得到了警告:控制​​到达非void函数结束

I run the following C codes and got a warning: control reaches end of non-void function

int main(void) {}

有什么建议?

推荐答案

只要把返回0 的main()。你的主函数返回一个int( INT主要(无效))因此,你应该添加在其末端有一个回报。

Just put return 0 in your main(). Your function main returns an int (int main(void)) therefore you should add a return in the end of it.

控制达到一个非void函数的末尾

Control reaches the end of a non-void function

Problem: I received the following warning:

警告:控制到达非void函数结束

warning: control reaches end of non-void function

解决方案:该警告是类似于在返回没有值描述的警告。如果控制到达一个函数的结尾,并没有遇到任何回报,GCC假设没有返回值回报。但是,对于此,该功能需要一个返回值。在函数的结尾,添加返回一个合适的返回值的return语句,即使控制永远不会到达那里。

Solution: This warning is similar to the warning described in Return with no value. If control reaches the end of a function and no return is encountered, GCC assumes a return with no return value. However, for this, the function requires a return value. At the end of the function, add a return statement that returns a suitable return value, even if control never reaches there.

<一个href=\"http://publib.boulder.ibm.com/infocenter/tpfhelp/current/index.jsp?topic=/com.ibm.ztpf-ztpfdf.doc_put.cur/gtpm1/m1rhnvf.html\"相对=nofollow>来源

解决方案

int main(void)
{
    my_strcpy(strB, strA);
    puts(strB);
    return 0;
}

这篇关于为什么&QUOT警告;控制到达非void函数&QUOT结束; main函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆