Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754328
  • 博文数量: 787
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5015
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-22 15:17
文章分类

全部博文(787)

文章存档

2008年(787)

我的朋友

分类:

2008-09-25 16:11:38

“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, "Programming languages - C", ISO/IEC 9899:1999(E)

[@more@]
拗口的话是“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”,分解一下,先看"calling the exit function 
with the value returned by the main function as its argument"。再分解,calling the exit function with the 
value as its argument,而returned by the main function是用来修饰value的(啊,让我想起了编译原理的树形语法
分析,一个结点一个结点地展开:)
到这儿分析工作就完成了。这一句话的大意就是,main函数的返回相当于调用exit函数,并把main函数的返回值作为exit
的参数。
把本段全文串一下:
如果main函数的返回值是和int兼容的类型,main函数的返回相当于调用exit函数,并把main函数的返回值作为exit的参
数;运行至main函数结尾的"}"将返回0。如果返回值和int不兼容,那么返回主机环境时的终止状态将是不确定的。
所以main的退出形式应该有以下两种:
int main()
{
}

int main()
{
return 0; //或其它一个int类型
}


--------------------next---------------------

阅读(623) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~