主要回报代码 [英] main return codes

查看:66
本文介绍了主要回报代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,该标准已经从函数main()(0,EXIT_SUCCESS,EXIT_FAILURE)定义了三个便携式返回

代码。就个人而言,在我使用的所有平台上都是
,EXIT_SUCCESS是,#define

EXIT_SUCCESS 0和EXIT_FAILURE是,#define EXIT_FAILURE 1。我有,

然而,被告知有几个平台反向定义两个

(#define EXIT_SUCCESS 1和#define EXIT_FAILURE 0)。如果这是真的,我会期望对几乎所有应用程序使用EXIT_SUCCESS或

EXIT_FAILURE这是常见的礼仪,并避免使用return

0;以免意图在那些不符合规范的平台上标记失败。但是,在我使用的大多数软件项目中,返回0和返回0。是我来的最常见的退货代码




你们都有什么想法?我已经开始将stdlib.h包含在我工作的所有软件项目中,并避免使用return 0;。只是

有点好奇你的意见。


谢谢你,


-

Sean

As far as I can tell, the standard has defined three portable return
codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally,
on all platforms I have worked with, EXIT_SUCCESS is, "#define
EXIT_SUCCESS 0" and EXIT_FAILURE is, "#define EXIT_FAILURE 1". I have,
however, been told that a few platforms define the two in reverse
(#define EXIT_SUCCESS 1 and #define EXIT_FAILURE 0). If this is true, I
would expect that it would be common etiquette to use EXIT_SUCCESS or
EXIT_FAILURE for nearly all applications and avoid the use of "return
0;" so as not to accidentally flag a failure on those platforms that do
not comply with the "norm". However, in most of the software projects I
have worked with, "return 0" is the most common return code I''ve come
across.

What do you all think? I''ve pretty much started including stdlib.h in
all software projects that I work on and avoid using "return 0;". Just
kind of curious what you opinions are.

Thank you,

--
Sean

推荐答案

Fao,Sean< en ********** @ yahoo.comi-want-no -spam>潦草地写道:
Fao, Sean <en**********@yahoo.comi-want-no-spam> scribbled the following:
据我所知,标准已经从函数main()(0,EXIT_SUCCESS,EXIT_FAILURE)定义了三个可移植的返回代码。就个人而言,在我使用过的所有平台上,EXIT_SUCCESS都是#define
EXIT_SUCCESS 0。和EXIT_FAILURE是,#define EXIT_FAILURE 1。但是,我已经被告知有几个平台将两者反向定义(#define EXIT_SUCCESS 1和#define EXIT_FAILURE 0)。如果这是真的,我希望对几乎所有的应用程序使用EXIT_SUCCESS或
EXIT_FAILURE是常见的礼仪,并避免使用return
0;以免在那些不符合规范的平台上意外标记故障。但是,在我使用过的大多数软件项目中,返回0和是我来过的最常见的返回代码。
你们都有什么想法?我已经开始将stdlib.h包含在我工作的所有软件项目中,并避免使用return 0;。只是好奇你的意见。
As far as I can tell, the standard has defined three portable return
codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally,
on all platforms I have worked with, EXIT_SUCCESS is, "#define
EXIT_SUCCESS 0" and EXIT_FAILURE is, "#define EXIT_FAILURE 1". I have,
however, been told that a few platforms define the two in reverse
(#define EXIT_SUCCESS 1 and #define EXIT_FAILURE 0). If this is true, I
would expect that it would be common etiquette to use EXIT_SUCCESS or
EXIT_FAILURE for nearly all applications and avoid the use of "return
0;" so as not to accidentally flag a failure on those platforms that do
not comply with the "norm". However, in most of the software projects I
have worked with, "return 0" is the most common return code I''ve come
across. What do you all think? I''ve pretty much started including stdlib.h in
all software projects that I work on and avoid using "return 0;". Just
kind of curious what you opinions are.




AFAIK,C标准定义0表示成功退出。所以

平台不允许#define EXIT_FAILURE 0.


-

/ - Joona Palaste(pa * ****@cc.helsinki.fi)-------------芬兰-------- \

\ ----- -------------------------------------------------- - 规则! -------- /

肯定很有钱和小鸡。

- Beavis和Butt-head



AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head


Joona I Palaste< pa ***** @ cc.helsinki.fi>写道:
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
Fao,Sean< en ********** @ yahoo.comi-want-no-spam>潦草地写道:
Fao, Sean <en**********@yahoo.comi-want-no-spam> scribbled the following:
据我所知,标准已经从函数main()(0,EXIT_SUCCESS,EXIT_FAILURE)定义了三个可移植的返回代码。就个人而言,在我使用过的所有平台上,EXIT_SUCCESS都是#define
EXIT_SUCCESS 0。和EXIT_FAILURE是,#define EXIT_FAILURE 1。但是,我已经被告知有几个平台将两者反向定义(#define EXIT_SUCCESS 1和#define EXIT_FAILURE 0)。如果这是真的,我希望对几乎所有的应用程序使用EXIT_SUCCESS或
EXIT_FAILURE是常见的礼仪,并避免使用return
0;以免在那些不符合规范的平台上意外标记故障。但是,在我使用过的大多数软件项目中,返回0和是我来过的最常见的返回代码。
As far as I can tell, the standard has defined three portable return
codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally,
on all platforms I have worked with, EXIT_SUCCESS is, "#define
EXIT_SUCCESS 0" and EXIT_FAILURE is, "#define EXIT_FAILURE 1". I have,
however, been told that a few platforms define the two in reverse
(#define EXIT_SUCCESS 1 and #define EXIT_FAILURE 0). If this is true, I
would expect that it would be common etiquette to use EXIT_SUCCESS or
EXIT_FAILURE for nearly all applications and avoid the use of "return
0;" so as not to accidentally flag a failure on those platforms that do
not comply with the "norm". However, in most of the software projects I
have worked with, "return 0" is the most common return code I''ve come
across.


你们都有什么想法?我已经开始将stdlib.h包含在我工作的所有软件项目中,并避免使用return 0;。只是好奇你的意见。
What do you all think? I''ve pretty much started including stdlib.h in
all software projects that I work on and avoid using "return 0;". Just
kind of curious what you opinions are.



AFAIK,C标准定义0表示成功退出。所以
平台不允许#define EXIT_FAILURE 0。



AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.




是的。 IIRC有问题的系统是MVS(也许是VMS;我从来没有使用过

,如果他们坚持使用这种可混淆的缩写词,我就会把它们归咎于责备...),EXIT_FAILURE #defined为2或其他一些

非零甚至整数,并且编译器在

屏幕后做了一些摆弄以确保程序退出后,返回值0被更改为奇数值



无论如何,0和EXIT_SUCCESS都必须返回成功的退出状态

到环境。有趣的是,没有任何东西要求它们都能获得相同的成功;我认为在一个系统中,b $ b将负值视为失败而非负视为成功,这是一个

实现,其中#defined EXIT_FAILURE为-1,EXIT_SUCCESS为1,

并将这些返回到环境不变,符合要求。

这将给C程序员两种成功的方法,但只有一种方式来支付
失败 - 这种情况与任何程序员的经历完全不一致,当然是
,但在这样的环境中编程一定很幸福:-)


Richard



Yes. IIRC the system in question is MVS (maybe VMS; I''ve never used
either, and if they insist on using such confusable abbreviations, I
hold them to blame...), EXIT_FAILURE was #defined to be 2 or some other
non-zero even integer, and the compiler did some fiddling behind the
screens to ensure that a return value of 0 was changed to an odd value
after the program exits.
In any case, both 0 and EXIT_SUCCESS must return a succesful exit status
to the environment. Interestingly, there''s nothing that demands that
they both return the same succesful; I suppose that on a sytem which
sees negative values as failure and non-negative as success, an
implementation which #defined EXIT_FAILURE as -1 and EXIT_SUCCESS as 1,
and returns these to the environment unchanged, would be conforming.
This would give the C programmer two ways to succeed, but only one to
fail - a situation completely at odds with any programmer''s experience,
of course, but it must be bliss to program in such an environment :-)

Richard


Joona I Palaste写道:
Joona I Palaste wrote:
AFAIK,C标准定义0表示成功退出。所以
平台不允许#define EXIT_FAILURE 0。
AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.




哦,我忘了提到我的整个帖子都假定那个人>
告诉我一些平台#define EXIT_FAILURE 0,实际上知道他们讨论的是什么
。我的整个论点都没有实际意义,如果他们只是随便吐出一堆热气;-)。


-

Sean



Oh, I forgot to mention that my entire post assumes that the people that
told me some platforms #define EXIT_FAILURE 0, actually knew what they
were talking about. My entire argument is moot if they''re just spitting
out a bunch of hot air ;-).

--
Sean


这篇关于主要回报代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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