为什么返回0可选? [英] Why is return 0 optional?

查看:115
本文介绍了为什么返回0可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么,如果我写

int main() 
{ 
    //... 
}

我不需要写返回0; 函数的结束?该编译器为我做呢?

do I not need to write return 0; at the end of the main function? Does the compiler do it for me?

我用GCC / C99。

I use GCC / C99.

推荐答案

最近C(目前这是C99的几个修订)返回 0 默认情况下,如果在函数的结尾没有明确return语句和控制流关闭功能的终端(见的 C99 TC3 )。这是因为大多数往往是这样写的回报这样的形式呢。

The most recent C (currently that's C99 with a few amendments) returns 0 from main by default if there is no explicit return statement at the end of the function, and control flows off the function's end (see 5.1.2.2.3 in C99 TC3). This is because most often one would write such a form of return anyway.

在C89,你需要有返回的东西 - 它没有这样的隐含回报。但是编译器是没有诊断这样的错误所需手段(见3.6.6.4在 C89在草案6.9.1 / 12 href=\"http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf\" rel=\"nofollow\"> C99 TC3 )。

In C89 you need to return something there - it has no such implicit return. But the compiler is by no means required to diagnose such a mistake (see 3.6.6.4 in the C89 draft and 6.9.1/12 in C99 TC3).

这篇关于为什么返回0可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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