473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 #1
17 2528
Quoth Tatu Portin on or about 2004-11-20:
Is FALSE == 0?
In other words, does 'function ()' execute on all platforms:


I asked a similar question recently. Here's the google archive
http://www.google.com/groups?selm=cn...s.uwaterloo.ca

-trent
Nov 14 '05 #2
Trent Buck wrote:
Quoth Tatu Portin on or about 2004-11-20:
Is FALSE == 0?
In other words, does 'function ()' execute on all platforms:

I asked a similar question recently. Here's the google archive
http://www.google.com/groups?selm=cn...s.uwaterloo.ca

-trent


From
http://www.google.com/groups?selm=cn...s.uwaterloo.caAll 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.
Also, I would like if one could point some place in standard (C89, C99) where
it defines these values.
Nov 14 '05 #3
In article <3h**************@read3.inet.fi>,
Tatu Portin <ax****@mbnet.fi> wrote:
Is FALSE == 0?
Yes.
if ( (1 == 2) == 0 )
function ();
Yes.
if ( (7!) == 0 )
function ();
No, this will not compile.

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

Yes.
I would like if you could point to some definition of the c language.


The ANSI/ISO/IEC 9899-1999 standard.

--
Göran Larsson http://www.mitt-eget.com/
Nov 14 '05 #4
Goran Larsson wrote:
In article <3h**************@read3.inet.fi>,
Tatu Portin <ax****@mbnet.fi> wrote:
Is FALSE == 0?


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


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


No, this will not compile.

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

Yes.
I would like if you could point to some definition of the c language.


The ANSI/ISO/IEC 9899-1999 standard.


Thanks. Just if you could give some www-adress for reference.
Nov 14 '05 #5
Tatu Portin wrote:
Goran Larsson wrote:
Tatu Portin <ax****@mbnet.fi> wrote:
I would like if you could point to some definition of the c
language.


The ANSI/ISO/IEC 9899-1999 standard.


Thanks. Just if you could give some www-adress for reference.


The standard is available for about 270 USD as paper copy or from
webstore.ansi.org 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.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #6
Tatu Portin wrote:
Goran Larsson wrote:
In article <3h**************@read3.inet.fi>,
Tatu Portin <ax****@mbnet.fi> wrote:
Is FALSE == 0?

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

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

No, this will not compile.

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

Yes.
I would like if you could point to some definition of the c language.

The ANSI/ISO/IEC 9899-1999 standard.


Thanks. Just if you could give some www-adress for reference.

I believe your c-book whichever it is should be able to answer this
question.
If it does not maybe you need another book.

--
Imanpreet Singh Arora
Nov 14 '05 #7
Michael Mair <Mi**********@invalid.invalid> writes:
[...]
The standard is available for about 270 USD as paper copy or from
webstore.ansi.org 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).

--
Keith Thompson (The_Other_Keith) 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 #8
Tatu Portin <ax****@mbnet.fi> writes:
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.


Read section 9 of the C FAQ, <http://www.eskimo.com/~scs/C-faq/top.html>.
(If you forget the URL, just google "C FAQ".)

--
Keith Thompson (The_Other_Keith) 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 #9
Hi Keith,

Keith Thompson wrote:
Michael Mair <Mi**********@invalid.invalid> writes:
[...]
The standard is available for about 270 USD as paper copy or from
webstore.ansi.org 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).


Mind the "quite" :-)
The OP asked for the standard, I gave the answer.
He can have a look at N869 and see and believe that going back to
"ordinary" C books might be a better idea. Sometimes, you have to
do it for yourself...
Apart from K&R2, I also always refer the people to the c.l.c FAQ.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #10
Tatu Portin <ax****@mbnet.fi> 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:
"Notwithstanding 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:
"Notwithstanding 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.fi> 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.fi> 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:
"Notwithstanding 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_valid(some_type argument);

and suppose you've defined

#define FALSE 0
#define TRUE 1

This is ok:

if (argument_is_valid(foo)) { ... }

This is needlessly verbose:

if (argument_is_valid(bar) == FALSE) { ... }

And this is dangerous:

if (argument_is_valid(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_Keith) 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.inet.fi>
Tatu Portin <ax****@mbnet.fi> 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.org> Keith Thompson <ks***@mib.org> writes:
Michael Mair <Mi**********@invalid.invalid> writes:
[...]
The standard is available for about 270 USD as paper copy or from
webstore.ansi.org 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**********@invalid.invalid> kirjoitti 20.11.2004:
The standard is available for about 270 USD as paper copy or from
webstore.ansi.org 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
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...
3
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...
15
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
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 {...
14
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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,...
0
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...

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.