RE: A quick c question

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 13 Mar 2008 18:32:25 -0400

You should not need to care about -1 or anything else, but instead just use
EOF

To answer your question, *smile*, try it, but here are my off the head
thoughts, which I'm pretty sure are correct in this case.

To answer your question: yes, 0 is false and anything else is true;
therefore, if c is -1 then if(c) gets executed, but if(!c) does not get
executed, not because !c necessarily equals 0 but because the ! Operator is
guaranteed to return the boolean opposite of what it is given, so since c is
true because it's not 0, then the opposite of anything that is true is false
... I can not stress enough that this does not make it 0, it just makes it
false, and there is a huge difference.

This is why you should always use constants such as eof, false, and true
instead of 0, -1 or whatever.

I hope this helps, just a little?

Take care,
Sina 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Daniel Dalton
Sent: Thursday, March 13, 2008 5:20 PM
To: blind programming
Subject: RE: A quick c question

Hi Sina,

On Wed, 12 Mar 2008, Sina Bahram wrote:

> I believe that is implementation specific; hence, the EOF constant is 
> available as a #define in most systems.

So on a linux box (debian) -1 sounds ok?
What does -1 mean in C?
false?
if I write:
int c =-1;
if (!c)
{...}
Will ... get executed?
Or is 0 false and all other negative numbers and positive numbers are true?

--
Daniel Dalton

http://members.iinet.net.au/~ddalton/
d.dalton@xxxxxxxxxxxx
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: