回报价值实践 [英] Return Value Practice

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

问题描述

您好,


如果从函数返回一个整数来通知成功或

错误,这通常表示0?例如:


int chk(int c){

...

}


int fn(int c){

if(chk(c)== 0){

printf(" Success\\\
);

}否则{

printf(" Error\ n);;

}

返回c;

}


查看chk(c)== 0和if语句的流程,与行

一起通常的做法是,声明是否正确?或者它应该变成

chk(c)!= 0?


谢谢 - 莱尔。

Hello,

In the case of returning an integer from a function to notify success or
error which does 0 customarily signify? For example:

int chk( int c ) {
...
}

int fn( int c ) {
if( chk( c ) == 0 ) {
printf( "Success\n" );
} else {
printf( "Error\n" );
}
return c;
}

Looking at chk( c ) == 0 and the flow of the if statement, to be in line
with common practice, is the statement correct as is? Or should it become
chk( c ) != 0?

Thanks - Lyle.

推荐答案

Lyle Fetterly写道:
Lyle Fetterly wrote:
你好,

在从函数返回一个整数来通知成功或
错误的情况下0通常表示?例如:
Hello,

In the case of returning an integer from a function to notify success or
error which does 0 customarily signify? For example:




如果有自定义,0通常表示成功。但是,如果您不熟悉某个特定的库函数,那么,在假设任何内容之前,请务必阅读文档。


-

======================================== ========== ======================

Ian Pilcher i。******* @ comcast.net

=========== ======================================= =========== ===========



To the extent that there is a custom, 0 usually signifies success. If
you''re unfamiliar with a particular library function, however, always
read the documentation before assuming anything.

--
================================================== ======================
Ian Pilcher i.*******@comcast.net
================================================== ======================


Lyle Fetterly写道:
Lyle Fetterly wrote:

在从中返回一个整数的情况下一个通知成功或错误的函数,它通常表示0?例如:

In the case of returning an integer from a function to notify
success or error which does 0 customarily signify? For example:




由于成功是缺少错误,并且可能存在多个

形式和错误类,因此实用信号成功与

a为零,错误详细信息为非零。假设没有其他

对返回值的限制。


-

"如果你想通过群发帖后续.google.com,不要使用

破损的回复链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson



Since success is the lack of errors, and there can be multiple
forms and classes of error, it is practical to signal success with
a zero, and error details with non-zero. Assuming no other
constrictions on the returned value.

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson




Lyle Fetterly写道:

Lyle Fetterly wrote:
你好,

在从函数返回一个整数以通知成功的情况
或0通常表示的错误?
Hello,

In the case of returning an integer from a function to notify success or error which does 0 customarily signify?




正如其他人提到的那样,它通常是成功,基本上意味着

没有错误代码。它也与main()的返回一致,其中0

与EXIT_SUCCESS相同(这并不是说EXIT_SUCCESS == 0

必然)。


Brian



As the others have mentioned, it''s typically success, basically meaning
no error code. It''s also in line with the return from main(), where 0
is the same as EXIT_SUCCESS (which is not to say that EXIT_SUCCESS == 0
necessarily).


Brian


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

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