boolean

Karl Heuer karl at haddock.ima.isc.com
Sun May 27 08:16:10 AEST 1990


In article <4232 at castle.ed.ac.uk> aipdc at castle.ed.ac.uk (Paul D. Crowley) writes:
>Peeve: why doesn't C have a type "boolean" built in?

Answer relative to Classic C: K and R wanted to keep the language small, and
decided that the more powerful% type "int" was sufficient.  (In fact, there's
evidence that at least one of them prefers to use an arithmetic type even in
a language that already supports booleans.)

Answer relative to ANSI C: because it wasn't within the charter of X3J11 to
invent new features without a compelling reason.  The idea was to standardize
the language, not build a new one.

Personal opinion: I'd have been satisfied with a typedef and two macro
constants (or enums), hidden in either <stddef.h> or a separate header
<bool.h>, with the compiler having the option of strictly enforcing the
boolean-only use of this type.

>I'm sure there's some compiler somewhere that could use it to
>improve executables.

There are some improvements that can be made (particularly in register
allocation for functions that have more than one boolean variable with auto
storage duration), but I think the more important improvement gain is in
reducing programmer error by enforcing the restricted rules.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint
________
% int *is* more powerful than boolean, but this doesn't make it a better tool.
(cf. the powerful flow control construct "goto".)



More information about the Comp.std.c mailing list