EXIT_FAILURE AND EXIT_SUCCESS
2014-05-09 00:00
281 查看
EXIT_FAILURE, either in a return statement in
mainor as an argument to
exit(), is the only portable way to indicate failure in a C or C++ program.
exit(1)can actually signal successful termination on VMS, for example.
If you're going to be using
EXIT_FAILUREwhen your program fails, then you might as well use
EXIT_SUCCESSwhen it succeeds, just for the sake of symmetry.
On the other hand, if the program never signals failure, you can use either
0or
EXIT_SUCCESS. Both are guaranteed by the standard to signal successful completion. (It's barely possible that
EXIT_SUCCESScould have a value other than 0, but it's equal to 0 on every implementation I've ever heard of.)
Using
0has the minor advantage that you don't need
#include <stdlib.h>in C, or
#include <cstdlib>in C++ (if you're using a
returnstatement rather than calling
exit()) -- but for a program of any significant size you're going to be including stdlib directly or indirectly anyway.
For that matter, in C starting with the 1999 standard, and in all versions of C++, reaching the end of
main()does an implicit
return 0;anyway, so you might not need to use either
0or
EXIT_SUCCESSexplicitly. (But at least in C, I consider an explicit
return 0;to be better style.)
相关文章推荐
- return EXIT_SUCCESS
- EXIT_SUCCESS_百度百科
- error LNK2005: __c_exit already defined in libcmt.lib(crt0dat.obj)
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
- _exit和exit的区别
- exit与_exit
- Ajax通过jsonp实现跨域访问,访问成功但走error不走success的的问题解决
- android自定义exittext和button
- php exit()函数
- 添加第三方类库造成的linker command failed with exit code 1 (use -v to see invocation)的错误调试
- JVM Terminated. Exit Code = 13
- No result defined for action com.xiao.action.Haha and result success
- Ajax通过jsonp实现跨域访问,访问成功但走error不走success
- Dell服务器MegaCli命令只返回Exit Code: 0x00问题分析
- 内核线程&&系统调用exit&&wait4&&撤销进程
- Jquery ajax json 不执行success的原因 坑爹
- finish/onDestroy/System.exit()的区别
- 【Android】System.exit(0) 退出程序
- c语言中exit的简单用法
- C#调用进程退出时ExitCode的作用