One of my friends asked a question, why is there no Boolean
data type in the C programming language. I did a bit of searching and reading. I got few questions and answers in stack overflow saying that,
- All data types should be addressable, and a bit cannot be addressed.
- The basic data structure at the hardware level of mainstream CPUs is a byte. Operating on bits in these CPUs require additional processing.
We can use a bool in this manner
#define bool int
#define TRUE 1
#define FALSE 0
or use typedef
s.
But my question is this: why wasn't it implemented as a data type in C, even after so many years. doesn't it make sense to implement a one byte data type to store a boolean value rather than using int
or short
explicitly.