I come from C++, and there's a type called "bool" in C++. It works
exactly like any other integer type except that when promoted, it
either becomes a one or a zero, so you can you bitwise operators as if
they were logical operators:
bool a = 5, b = 6;
if (a == b) DoSomething; /* This will execute */
What type is commonly used in C for playing around with boolean
values?
I'm writing code for an embedded systems project so I'll *really* have
to watch how much memory I'm using... so would it be wise to be
returning "int" from functions that I would otherwise (in C++) return
a bool from? For example
int QueryBit(char unsigned const *const pc, unsigned const index)
{
return *pc & (1U << index);
}
(Let's leave alone for the moment the issue of whether this should
instead be a macro)
I suppose I'm asking two questions:
a) What type is commonly used for booleans?
b) What type is commonly used for booleans when you've to go easy
on memory consumption?
Martin
Comment