Alex Rivera | Logout

Why didn't C have a boolean data type prior to C99?

Asked 2010-03-11T15:03:51.547
51

I realise you can just #define some integers, but why didn't C have a dedicated boolean data type before C99?

It's such a common occurence in programming and logic, I don't understand the absense of an explicit type and notation.

Edit
Report

3 Answers

17

C is actually little more than a higher-level assembly language. Yes, it got control structures and whatnot and it even got types which assembler certainly doesn't need.

But the language was designed decades ago. And since every boolean result gets down to individual bits in the processor's status word it obviously was sufficient to just using an integral data type for it. And it made the compiler probably a little less complex since you can omit some type checking (in later languages control structures need a boolean value, in C they just need an integral value of either 0 or something else).

answered 2010-03-11T15:09:32.377
5

Historical reasons, probably:

CPL, which was heavily influenced by ALGOL, most likely had a boolean type, but my google-fu didn't suffice to find a reference for this. But CPL was too ambitious for its time, resulting in a stripped-down version called BCPL, which had the benefit that you could actually implement it on available hardware.

BCPL only had a single type - the 'word' - which was interpreted as false in boolean contexts if 0 and as true if ~0 (meaning the complement of 0, which would represent the value -1 if interpreted as signed twos-complement integer). The interpretation of any other value was implementation dependant.

After the still typeless successor B, C reintroduced a type system, but it was still heavily influenced by the typeless nature of its predecessors.

answered 2010-03-11T15:55:31.707
0

Because none can foresee everything including missing data type in a programming language.

answered 2010-03-11T15:08:48.640

Your Answer