Why was the boolean data type not implemented in C

That's not true any more. The built-in boolean type, aka _Bool is available since C99. If you include stdbool.h, its alias bool is also there for you.


_Bool is a true native type, not an alias of int. As for its size, the standard only specifies it's large enough to store 0 and 1. But in practice, most compilers do make its size 1:

For example, this code snippet on ideone outputs 1:

#include <stdio.h>
#include <stdbool.h>
int main(void) {
    bool b = true;
    printf("size of b: %zu\n", sizeof(b));
    return 0;
}

C99 added support for boolean type _Bool, is not simply a typedef and does not have to be the same size as int, from the draft C99 standard section 6.2.5 Types:

An object declared as type _Bool is large enough to store the values 0 and 1.

We have convenience macros through the stdbool.h header. we can see this from going to the draft C99 standard section 7.16 Boolean type and values whcih says:

The header defines four macros.

The macro

bool

expands to _Bool.

The remaining three macros are suitable for use in #if preprocessing directives. They are

true

which expands to the integer constant 1,

false

which expands to the integer constant 0, and

__bool_true_false_are_defined

which expands to the integer constant 1.

Tags:

C

Boolean