LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 708|回复: 1

ISO C的main的退出

[复制链接]
发表于 2005-5-17 15:42:33 | 显示全部楼层 |阅读模式
“If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value
returned by the main function as its argument; reaching the } that terminates the
main function returns a value of 0. If the return type is not compatible with int, the
termination status returned to the host environment is unspecified.”
5.1.2.2.3  Program termination, ISO/IEC 9899:1999(E)

这段话比较拗口,对于main的退出,return 0; 这句是可选还是必须的? :ask
发表于 2005-5-17 16:34:06 | 显示全部楼层
从上面的话看return 0;并不是必须的。当main的返回类型是兼容与int时,如果你没有明确写出return语句那么当程序执行到},也就是正常结束时它会返回一个0值。如果返回类型不兼容int那么这种情况是未定义的。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表