退出功能的疑问 [英] exit function doubts

查看:75
本文介绍了退出功能的疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在程序中的许多地方,我看到调用exit()并以2作为参数传递给它.
exit(2);

这2代表什么?
我可以获取所有要退出的此类参数的列表吗?

解决方案

这只是退出状态. 0表示成功退出,而其他任何整数值都表示某种失败.
失败的特定值特定于开发人员希望达到的目标,并且没有成功以外的任何预设值(0除外).

C ++ Exit() [


<像常规函数的return value一样,blockquote>函数确实为整个应用程序指定一个返回值(并终止该返回值).在呼叫方,称为
ExitCode [错误级别 [Windows Shell命令 [ ^ ]).
含义不是那么普遍.零(或未指定的值)表示成功执行,其他值表示故障...


At many places in program I see exit() being called with 2 passed as parameter to it.
exit(2);

What does this 2 stands for?
Can I get a list all such parameters to exit?

解决方案

It is simply an exit status. 0 indicates a successful exit, while any other integer value indicates a failure of some kind.
The particular value of the failure is specific to whatever the developer wants it to be and doesn''t have any preset values other than 0 for success.

C++ Exit()[^]


Exit causes your process to stop executing immediately, and returns an integer code - it is a relic of the MSDOS days when the only thing a program could return was an integer.

Then as now the value returned was zero for success - a normal termination - and non-zero for a failure of some kind. The meaning of the non-zero value is system dependant so there is no meaningful list of codes that is guaranteed to be relevant to your application. Even in the DOS days, program return values meant something to the author of the program, and frequently nothing to anyone else!

If your code is liberally sprinkled with numeric constants rather than mnemonics, then someone has done a lazy job of coding and all you can do it hope that they have documented the value "2" clearly somewhere.


Like the return value of regular functions the exit(value) function does specify a return value for the whole application (and terminates it). On caller side is called ExitCode[^], but also ERRORLEVEL[^] in case of the command shell for example. As this is quite common (available on Windows, Unix, Linux and also other OS), should be considered a one byte value - but higher values can be also used on some operating systems (like for windows shell commands[^]).
The meaning is not so common. Zero (or nonspecified value) means successful execution, other values means trouble...


这篇关于退出功能的疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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