返回a == b; [英] return a==b;
问题描述
我不记得确切的语法,但是我听说
返回a == b;
是有效的c(就像在gcc中一样)不抱怨)
我的问题:
1)这是真正的C标准吗?
2)因为C中没有真或假(只有0而不是0)
a == b有什么值,如果有的话?
thanx
olivier
I don''t remember the exact syntax, however I''ve heard that
return a==b;
is valid c (like in gcc does not complain)
my questions:
1) is this real C standard?
2) as there is no true nor false in C (just 0 and not 0) what does
a==b have for a value, if any?
thanx
olivier
推荐答案
去******* @ olive- it.ch 写道:
我不记得确切的语法,但是我听说过
返回a == b;
是有效的c(就像在gcc中没有抱怨)
我的问题:
1)这是真正的C标准?
I don''t remember the exact syntax, however I''ve heard that
return a==b;
is valid c (like in gcc does not complain)
my questions:
1) is this real C standard?
是
yes
2)因为C中没有true或false(只有0而不是0) )
a == b有什么值,如果有的话?
2) as there is no true nor false in C (just 0 and not 0) what does
a==b have for a value, if any?
0如果a和不同,某些实现定义的值不是0,如果
它们相等(通常为1)。
0 if a and be differ, some implementation-defined value other than 0 if
they''re equal (usually 1).
thanx
olivier
thanx
olivier
-
Pietro Cerutti
--
Pietro Cerutti
go ******* @ olive-it.ch 说:
我不记得确切的语法,但是我听说过
返回a == b;
有效c
I don''t remember the exact syntax, however I''ve heard that
return a==b;
is valid c
它是。
It is.
(比如在gcc中没有抱怨)
我的问题:
1)这是真正的C标准吗?
(like in gcc does not complain)
my questions:
1) is this real C standard?
是。
Yes.
2)因为C中没有真或假(只有0而不是0)
a == b有什么值,如果有的话?
2) as there is no true nor false in C (just 0 and not 0) what does
a==b have for a value, if any?
==产生0(a和b具有不同的值)或1(a和b具有
相同的值),保证。
一个等式表达式仍然是一个表达式,所以在返回语句中使用
它没有问题。
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
== yields either 0 (a and b have different values) or 1 (a and b have the
same value), guaranteed.
An equality expression is still an expression, so there is no problem using
it in a return statement.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Pietro Cerutti说:
Pietro Cerutti said:
去******* @ olive-it.ch 写道:
>我不知道不记得确切的语法,但我听说
返回== b;
是有效的c(就像在gcc中没有抱怨)
我的问题:
1)这是真正的C标准吗?
>I don''t remember the exact syntax, however I''ve heard that
return a==b;
is valid c (like in gcc does not complain)
my questions:
1) is this real C standard?
yes
yes
> 2)因为C中没有真或假(只有0和0)不是0)如果有的话,
a == b有什么价值?
>2) as there is no true nor false in C (just 0 and not 0) what does
a==b have for a value, if any?
0如果a和不同,某些实现定义的值不是0,如果
它们相等(通常为1)。
0 if a and be differ, some implementation-defined value other than 0 if
they''re equal (usually 1).
这不是我读标准的方式。请你提供章节和
诗? (我的是3.3.8:每个运算符<(小于),(大于/ b $ b),< =(小于或等于),> =(更大如果指定的关系为真,则
将产生1,如果为假,则为0。和
3.3.9:==(等于)和!=(不等于)运算符
类似于关系运算符,除了它们的优先级较低。
强烈表明==必须产生无论是0还是1.如果它实际上是实现定义的,那么标准会在某个地方记录这个事实,
但我找不到这样的参考。) />
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-http:/ /万维网。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
That''s not how I read the Standard. Could you please provide chapter and
verse? (Mine are 3.3.8: "Each of the operators < (less than), (greater
than), <= (less than or equal to), and >= (greater than or equal to) shall
yield 1 if the specified relation is true and 0 if it is false." and
3.3.9: "The == (equal to) and the != (not equal to) operators are
analogous to the relational operators except for their lower precedence".
This suggests strongly that == must yield either 0 or 1. If it''s actually
implementation-defined, the Standard will document this fact somewhere,
but I can find no such reference.)
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
这篇关于返回a == b;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!