I was just writing code in C and it turns out it doesn’t have a boolean/bool datatype. Is there any C library which I can include to give me the ability to return a boolean/bool datatype?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have a compiler that supports C99 you can
Otherwise, you can define your own if you’d like. Depending on how you want to use it (and whether you want to be able to compile your code as C++), your implementation could be as simple as:
In my opinion, though, you may as well just use
intand use zero to mean false and nonzero to mean true. That’s how it’s usually done in C.