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