473,698 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is FALSE == 0?

Is FALSE == 0?
In other words, does 'function ()' execute on all platforms:

if ( (1 == 2) == 0 )
function ();

if ( (7!) == 0 )
function ();

I would like if you could point to some definition of the c language.
Nov 14 '05
17 2550
Tatu Portin <ax****@mbnet.f i> wrote:
Trent Buck wrote:
Quoth Tatu Portin on or about 2004-11-20:
Is FALSE == 0?
In other words, does 'function ()' execute on all platforms:All operators that return a boolean result are defined to return 0 or
1, so you can do this, or at least could if you didn't mind inverting
the result.


"Are defined to return 0 or 1", but does not say whetever 0 is false or not.


FALSE and false are not part of C. So please rephrase
your question.
Also, I would like if one could point some place in standard
(C89, C99) where it defines these values.


FALSE is not defined anywhere. The section on operators says what
the result of each operator is.
Nov 14 '05 #11
On 20 Nov 2004 21:10:57 -0800, in comp.lang.c , ol*****@inspire .net.nz (Old
Wolf) wrote:
FALSE and false are not part of C. So please rephrase
your question.


Incorrect.

false is a macro defined as zero in stdbool.h

Note however this final sentence:
"Notwithstandin g the provisions of 7.1.3, a program may undefine and
perhaps then redefine the macros bool, true, and false"
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #12
Mark McIntyre wrote:
On 20 Nov 2004 21:10:57 -0800, in comp.lang.c , ol*****@inspire .net.nz (Old
Wolf) wrote:

FALSE and false are not part of C. So please rephrase
your question.

Incorrect.

false is a macro defined as zero in stdbool.h

Note however this final sentence:
"Notwithstandin g the provisions of 7.1.3, a program may undefine and
perhaps then redefine the macros bool, true, and false"


Well, I meant that false in general. Like: Is ((1 == 2) == 0)?
Nov 14 '05 #13
On Sun, 21 Nov 2004 13:34:33 GMT, in comp.lang.c , Tatu Portin
<ax****@mbnet.f i> wrote:

Well, I meant that false in general. Like: Is ((1 == 2) == 0)?


That remark makes no sense.... you need some context for it.

Anyhoo...

The effect of the equality operator is an int with value either one or zero
as appropriate (6.5.9(4)). The macros true and false are defined suitably
(7.16).

What more do you need to know?


--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #14
Tatu Portin <ax****@mbnet.f i> writes:
Mark McIntyre wrote:
On 20 Nov 2004 21:10:57 -0800, in comp.lang.c , ol*****@inspire .net.nz (Old
Wolf) wrote:
FALSE and false are not part of C. So please rephrase
your question. Incorrect. false is a macro defined as zero in stdbool.h Note
however this final sentence:
"Notwithstandin g the provisions of 7.1.3, a program may undefine and
perhaps then redefine the macros bool, true, and false"


This is a new feature in C99.
Well, I meant that false in general. Like: Is ((1 == 2) == 0)?


The relational operators yield either 0 (for false) or 1 (for true),
as do the "&&", "||", and "!" operators.

A function that returns a value to be used as a condition (e.g., in an
if statement) must return 0 for false, but may return any non-zero
value for true. This includes functions like isdigit() declared in
the standard header <ctype.h>.

The language *could* have been defined so that the relational
operators may yield any non-zero result when the condition is true,
but they were restricted to 0 and 1 for consistency. As a matter of
style, I don't recommend depending on this.

Whenever you test a value that represents a logical (boolean) result,
assume that any non-zero value can be used to represent truth. For
example, suppose you have a function

int argument_is_val id(some_type argument);

and suppose you've defined

#define FALSE 0
#define TRUE 1

This is ok:

if (argument_is_va lid(foo)) { ... }

This is needlessly verbose:

if (argument_is_va lid(bar) == FALSE) { ... }

And this is dangerous:

if (argument_is_va lid(baz) == TRUE ) { ... }

because the function could return 2 to indicate that the argument is
valid.

But using "return TRUE;" or "return FALSE;" in the body of the
function is just fine.

Never compare a boolean value against TRUE or FALSE.

(C99 changes this a bit by introducing a predefined type _Bool or
bool, and predefined values true and false.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #15
In article <news:JP******* *******@read3.i net.fi>
Tatu Portin <ax****@mbnet.f i> wrote:
Well, I meant that false in general. Like: Is ((1 == 2) == 0)?


If I may use a rather ... earthy analogy (which should at least be
unforgettable! :-) ), you can consume many kinds of food and drink:
plain water, orange juice, potatos, chicken, perhaps even lutefisk.
But your digestion of these inputs will only ever produce two kinds
of output, which some call "number one" and "number two"; or as a
friend of mine once called them, "stream output" and "core dumps".

C's relational and logical operators can consume many kinds of
input, but produce only two outputs. For something like:

if (x) {
truestuff();
} else {
falsestuff();
}

C will take the truestuff() branch if x is not zero, and the
falsestuff() branch if x is zero. But for:

int result = (x == y);

result will be 1 -- just just "any nonzero value", but exactly 1
-- if x == y, and 0 (the only "false" value) if x != y.

Note that the functions in <ctype.h>, such as isdigit() and isalpha(),
are *not* required to produce just 0 or 1, and often do not.

Because the logical operators force "any nonzero value" to become
1, and because the "!" (logical-not) operator is its own inverse,
you can use a double negation to "normalize" a boolean result:

int normalized = !!f();

Now "normalized " is 1 if f() returned nonzero, and 0 if f()
returned 0. If for some strange reason you want a "normalized "
version of, e.g., isalpha(), you can write:

int one_if_isalpha = !!isalpha(ch);

The same works for the other logical operators (&& and ||), so you
can also normalize by &&-ing with 1, or ||-ing with 0:

int normalized_via_ AND = f() && 1;
int normalized_via_ OR = f() || 0;

but I think these are even odder-looking than the "!!" normalization
method.

I leave it up to the reader to decide which of 0 and 1 correspond
to the, er, "stream output" and "core dump". :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #16
In <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes:
Michael Mair <Mi**********@i nvalid.invalid> writes:
[...]
The standard is available for about 270 USD as paper copy or from
webstore.ansi.o rg for 18 USD as .pdf file.
(
http://webstore.ansi.org/ansidocstor...EC+9899%2D1999
)

For most beginners, N869, the last public (and freely available) draft
is quite enough. Use google to obtain it.


For most beginners, a good book is going to be much more useful than a
copy of the standard. K&R2 is one of the best (_The C Programming
Language_, 2nd Edition, by Kernighan & Ritchie).


And for ALL posters, reading the FAQ before posting is a *must*!

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #17
Michael Mair <Mi**********@i nvalid.invalid> kirjoitti 20.11.2004:
The standard is available for about 270 USD as paper copy or from
webstore.ansi.o rg for 18 USD as .pdf file.


It is also available hardbound from Wiley for the price of a computer
book (Amazon.com's current price appears to be 57,20 USD). I find that
its lack of an un-nice license more than offsets the greater price
compared to the PDF.
--
Antti-Juhani Kaijanaho http://antti-juhani.kaijanaho.info/

Blogi - http://kaijanaho.info/antti-juhani/blog/
Toys - http://www.cc.jyu.fi/yhd/toys/
Nov 14 '05 #18

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

Similar topics

10
1763
by: Sylvain Thenault | last post by:
Hi there ! Can someone explain me the following behaviour ? >>> l = >>> 0 in (l is False) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument required >>> (0 in l) is False
3
2570
by: drs | last post by:
I just upgraded my Python install, and for the first time have True and False rather than 1 and 0. I was playing around at the command line to test how they work (for instance, "if 9:" and "if True:" both lead to the conditional being executed, but True == 9 -> False, that this would be true was not obvious to me -- "True is True" is True, while "9 is True" is false even though 9 evaluates to True.) Anyhow, in doing my tests, I...
15
2324
by: F. Da Costa | last post by:
Hi all, Following two sniperts of code I'm using and getting very interesting results from. ..html <tr id="1" class="segment" open="false"> This is the segment under 'investigation' ..js
10
3302
by: tony | last post by:
Hello!! I have some demo programs written in C# and they have this construction "" see below. I haven't seen this before so what does it mean ? public bool ShowDropDownButtons { get { return showDropDownButtons; }
14
3326
by: Prateek | last post by:
I've been using Python for a while (4 years) so I feel like a moron writing this post because I think I should know the answer to this question: How do I make a dictionary which has distinct key-value pairs for 0, False, 1 and True. As I have learnt, 0 and False both hash to the same value (same for 1 and True). {0: 'abc'} # Am I the only one who thinks this is weird?
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8893
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7723
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.