在C ++中定义逻辑真? [英] Definition of logical true in C++?

查看:78
本文介绍了在C ++中定义逻辑真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我定义了一个函数,那么在出现错误时将返回-1,否则将返回

正值:


int foo(int param ){

if(outOfRange(param))

返回-1;


return(param!= 0);

}


我可以依赖这段代码一直工作,还是

return语句可能产生-1也,在特定的编译器/操作系统上?

这是在某处定义的吗?如果是这样,标准中的哪个位置?


最好的问候,


Lars

If I define a function, that shall return -1 in case of error, and a
positive value otherwise:

int foo (int param) {
if (outOfRange (param))
return -1;

return (param != 0);
}

can I rely on this code always working, or is it possible that the
return statement produces a -1 also, on a specific compiler / OS?
Is this defined somewhere? And if so, where in the standard?

Best Regards,

Lars

推荐答案

Lars Uffmann写道:

Lars Uffmann wrote:


我可以依赖这段代码一直工作,还是有可能

return语句在特定的编译器/操作系统上也产生-1?

这是在某处定义的吗?如果是这样,标准中的哪个位置?
can I rely on this code always working, or is it possible that the
return statement produces a -1 also, on a specific compiler / OS?
Is this defined somewhere? And if so, where in the standard?



由4.5 / 4定义,布尔值true提升为1,布尔值false为0.

-

Sebastian Redl

As defined by 4.5/4, boolean true is promoted to 1, boolean false to 0.
--
Sebastian Redl


Sebastian Redl写道:
Sebastian Redl wrote:

由4.5 / 4定义,布尔值为true提升为1,布尔值为0.
As defined by 4.5/4, boolean true is promoted to 1, boolean false to 0.



谢谢,这就是我需要知道的全部 - 尽管我只是注意到有

不容易找到C ++标准的在线版本 - 你能够将b $ b指向我吗?


最好的问候,


Lars

Thanks, that''s all I needed to know - though I just noticed that there''s
no easily found online version of the C++ standards - are you able to
point me to one?

Best Regards,

Lars


Lars Uffmann写道:
Lars Uffmann wrote:

Sebastian Redl写道:
Sebastian Redl wrote:

>由4.5 / 4定义,布尔值true提升为1,布尔值false提升为0.
>As defined by 4.5/4, boolean true is promoted to 1, boolean false to 0.



谢谢,这就是我需要知道的全部 - 尽管我只是注意到了

在网上很难找到C ++标准的离子 - 你能够将b $ b指向我吗?


Thanks, that''s all I needed to know - though I just noticed that there''s
no easily found online version of the C++ standards - are you able to
point me to one?

http://webstore.ansi.org/RecordDetai...IEC+14882-2003


-

Ian Collins。

http://webstore.ansi.org/RecordDetai...IEC+14882-2003

--
Ian Collins.


这篇关于在C ++中定义逻辑真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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