Which numbers evaluate to true and false?

T

Thad Smith

August said:
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
 
M

Martin Ambuhl

August said:
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

August Karlstrom

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

A mutual conclusion, I think ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top