[sdiy] Quick C query
Andre Majorel
aym-htnys at teaser.fr
Sun Nov 21 16:04:22 CET 2010
On 2010-11-21 13:31 +0000, Tom Wiltshire wrote:
> What's the best way to deal with booleans in C? I see that we don't
> have a Boolean type explicitly.
> Presumably there's a standard practice for this, since I'm not the
> first person to need a boolean.
Zero is false, non-zero is true. Any signed or unsigned integral
type will do. The default integral type in C is "int" but you
can use "char" or individual bits if you're tight on memory.
Some feel better after
typedef sometype bool_t;
#define TRUE 1
#define FALSE 0
but that's really not necessary. It leads to code like
if (b == TRUE)
which is not only pleonastic but also incorrect because if b
ever happens to be non-zero but different from 1, this test
would consider it false even though it's really true.
--
André Majorel http://www.teaser.fr/~amajorel/
More information about the Synth-diy
mailing list