Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2314874
  • 博文数量: 527
  • 博客积分: 10343
  • 博客等级: 上将
  • 技术积分: 5565
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-26 23:05
文章分类

全部博文(527)

文章存档

2014年(4)

2012年(13)

2011年(19)

2010年(91)

2009年(136)

2008年(142)

2007年(80)

2006年(29)

2005年(13)

我的朋友

分类: C/C++

2010-08-01 12:10:26

当然, 这个毫无争议, 应该由程序员显式提供, 但作者对此的说明, 对于现今的ANSI C在技术上却不再适用:

大多数C语言实现都通过函数main的返回值来告知操作系统该函数的执行是成功还是失败. 处理方案是, 返回值为0代表程序执行成功, 返回值非0表示程序执行失败, 在使用一个软件管理系统, 该系统关注程序被调用后执行是成功还是失败, 那么很可能得到令人惊讶的结果.

说的是这样的程序:
main()
{
}

标准C中这样描述:
If the return type of the main function is a type compatible with int, ... 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.

对于上例, main没有显式声明返回值, 默认为int, 所以符号所谓"return type is compatible with int"

用VC2008试验多次, 全部返回0.

所以这个条款应该改为建议提供返回值, 而不视之为技术上的一个错误.
阅读(734) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~