Richard said:
Obviously. But that isn't the issue.
However it is one possible reason why C's designers did not consider a
dedicated boolean type as important.
So shall we get rid of ALL types and use typedefs?
You cannot get rid of some types without destroying the core language.
Also note that typedef cannot be used without the presence of at least
one preexisting type.
This is true of ANY language I have dealt with.
if(x) .....
The following is an excerpt from Wikipedia's article on C#:
C# supports a strict boolean type, bool. Statements that take
conditions, such as while and if, require an expression of a boolean
type. While C++ also has a boolean type, it can be freely converted to
and from integers, and expressions such as if(a) require only that a is
convertible to bool, allowing a to be an int, or a pointer. C#
disallows this 'integer meaning true or false' approach on the grounds
that forcing programmers to use expressions that return exactly bool
prevents certain types of programming mistakes.
Aha. So not so silly and "useless" after all?
I never said a boolean type was silly or useless. It's just not an
essential type however.
I would agree that is silly.
OP's statement isn't silly. A multi bit boolean type _does_ waste some
space. As in many other things, it's a matter of trade-off between
various competing considerations and C had, until C99, chosen not to
implement a boolean type. Now it has one, but not, apparently, to the
OP's satisfaction.
It is fairly clear to me that a boolean type would only make code
cleaner.
It might. OTOH the "type explosion" introduced by C99 can also be argued
as, to an extent, damaging one of C's strengths - it's simplicity.
Would I use them? Probably not :-; I'm too entrenched in zero
and non zero.
Personally I use boolean objects only occasionally. I use C99's
definition when it's available or define it myself. As Malcolm notes,
there is a small possibility of a non-Standard definition conflicting
with another definition in library code, but I haven't encountered that
problem yet.