Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Which numbers evaluate to true and false?

Reply
Thread Tools

Which numbers evaluate to true and false?

 
 
Thad Smith
Guest
Posts: n/a
 
      10-06-2005
August Karlstrom wrote:

> The real virtue of the bool type is that it conveys more information
> compared to an int used as a boolean type. You never need comments as
> "non-zero if... and zero if...". You still need to know though that it
> is really just an int and that zero is interpreted as `false' and
> non-zero as `true'.


Yes, easier documentation is an advantage and I use it with C90
compilers by declaring a typedef for bool or boolean. Then you can
document as you say. Another good strategy is to choose a boolean
variable name that implies the true state:

bool valveOpen; /* valve is currently open */

as opposed to

bool valveState; /* valve position: 1=open, 0=closed */

Thad

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      10-06-2005
August Karlstrom wrote:

> I assume the p suffix stands for "predicate", right? This is a kind of
> Hungarian notation that is common practice in languages that lacks a
> boolean type, e.g. Emacs lisp. With a boolean type there's no need for
> obscure naming, we just go:


Since your answer is completely nonresponsive, I suppose that means you
actually have nothing to say.
 
Reply With Quote
 
 
 
 
August Karlstrom
Guest
Posts: n/a
 
      10-06-2005
Martin Ambuhl wrote:
> August Karlstrom wrote:
>
>> I assume the p suffix stands for "predicate", right? This is a kind of
>> Hungarian notation that is common practice in languages that lacks a
>> boolean type, e.g. Emacs lisp. With a boolean type there's no need for
>> obscure naming, we just go:

>
>
> Since your answer is completely nonresponsive, I suppose that means you
> actually have nothing to say.


A mutual conclusion, I think
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[False,True] and [True,True] --> [True, True]????? bdb112 Python 45 04-29-2009 02:35 AM
evaluate NULL to a pointer which a CONST pointer points to G C++ 3 01-08-2007 04:22 PM
Why would this IF statement evaluate as TRUE? Steve Javascript 5 12-07-2004 07:02 AM
Can't get a db value to evaluate to TRUE...why? darrel ASP .Net 8 02-11-2004 01:43 PM
NULL: Is it guaranteed to evaluate 'not true' Mark A. Odell C Programming 19 09-30-2003 01:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57