473,509 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the value of relational expression

Hi!

In some compiler, the relational expression's value is 1 for true or 0 for
false. Is this a stardard? Or is there any other compilers which use 0 and
other Non-zero value?

Thank you!
Sunner Sun
Nov 14 '05 #1
4 2255
Sunner Sun <su********@163.com> scribbled the following:
Hi! In some compiler, the relational expression's value is 1 for true or 0 for
false. Is this a stardard? Or is there any other compilers which use 0 and
other Non-zero value?


All comparison operators ==, !=, <, >, <= and >= are guaranteed to
return 1 for true and 0 for false. However, any non-zero value can be
used for true in conditional statements.
For example:
int a = 2==2; /* a is guaranteed to be 1 */
if (2) {
printf("This is guaranteed to be executed\n");
}

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Bad things only happen to scoundrels."
- Moominmamma
Nov 14 '05 #2
"Sunner Sun" <su********@163.com> writes:
In some compiler, the relational expression's value is 1 for true or 0 for
false. Is this a stardard?
Yes.
Or is there any other compilers which use 0 and other Non-zero
value?


Not C compilers.
--
"This is a wonderful answer.
It's off-topic, it's incorrect, and it doesn't answer the question."
--Richard Heathfield
Nov 14 '05 #3
On Thu, 1 Apr 2004 14:31:01 +0800, "Sunner Sun" <su********@163.com>
wrote in comp.lang.c:
Hi!

In some compiler, the relational expression's value is 1 for true or 0 for
false. Is this a stardard? Or is there any other compilers which use 0 and
other Non-zero value?

Thank you!
Sunner Sun


The C standard specifies that all relational operators produce a value
of 1 for a true condition, and 0 for a false one. That is absolutely
standard, and no C compiler in existence is likely to get this wrong.

That said, the "as-if" rule allows a compiler to skip producing that
value unless it is actually used as a value, as long as it correctly
recognizes the truth or falsehood of the expression.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
In <c4**********@news.yaako.com> "Sunner Sun" <su********@163.com> writes:
In some compiler, the relational expression's value is 1 for true or 0 for
false. Is this a stardard? Or is there any other compilers which use 0 and
other Non-zero value?


How about reading the FAQ *before* posting?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
380
by: Sunner Sun | last post by:
Hi! In some compiler, the relational expression's value is 1 for true or 0 for false. Is this a stardard? Or is there any other compilers which use 0 and other Non-zero value? Thank you!...
24
3765
by: David Mathog | last post by:
If this: int i,sum; int *array; for(sum=0, i=0; i<len; i++){ sum += array; } is converted to this (never mind why for the moment):
23
2138
by: bjk of course | last post by:
hello, I've stumbled upon this in some code: n = !!x; I've ran it and 'n' is always either 0 or 1. Is '!!' an operator (what's it called?) and is it standard/portable? --
49
14856
by: raju | last post by:
hi can we compare two integers without using relational operators (== != < <= > >=) thanks rajesh s
669
25396
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
34
3556
by: emrahayanoglu | last post by:
Hello Everyone, Now, I'm working on a new web framework. I tried many test on the other programming languages. Then i decided to use python on my web framework project. Now i want to listen...
38
2474
by: DaVinci | last post by:
#include<stdio.h> #include<stdlib.h> #include<string.h> #define SECONDS_PER_YEAR (60*60*24*365)UL int main() { unsigned long int u_i = SECONDS_PER_YEAR; printf("%lu\n",u_i);
14
2539
by: AliceB.Toklas | last post by:
In my Absolute Beginner's Guide to C book by Greg Perry where it is instruction how relational operators work it gives the following example: int i = 5; so the following statement is true: ...
1
2207
by: muniba | last post by:
Relational algebric expression for the following: Draw two relational algebra query trees for the following query and show that one query tree is more eficient than the other. "Give the number...
13
1587
by: sulyokpeti | last post by:
I have made a simple python module to handle SQL databases: https://fedorahosted.org/pySQLFace/wiki Its goal to separate relational database stuff (SQL) from algorythmic code (python). A SQLFace...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.