+ 3

Boolean in c

Hey, I want to create a custom header for Boolean in c language. How can I do that? I just defined true as 1 and false as 0 and I don't know what to do next. I'm new in C. I have written only LinkedList implementation and couple of excercises on c basics

30th Jun 2019, 1:42 PM
Lighton
Lighton - avatar
5 Answers
+ 2
It already exists in the standard library. You can simply include <stdbool.h> to your program and then you'd access to predefined macros `bool`, `true`, and `false`. https://en.cppreference.com/w/c/types/boolean
30th Jun 2019, 2:24 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
+ 1
I tried this and it doesn't work https://code.sololearn.com/cfWDEx15QtLH/?ref=app
30th Jun 2019, 2:06 PM
Lighton
Lighton - avatar
+ 1
I don't need use booleans yet! I just want to implement them on my own for educational purposes
30th Jun 2019, 2:26 PM
Lighton
Lighton - avatar
+ 1
I see. Let's begin with the first issue. enum cBool {true, false}; by default, the value of the first enumerator (true) start off with `0`, which means you should've begun with `false` as enum cBool {false, true}; Next is the way the enumeration instance `isTrue` has been defined. Since the enum type `cbool` hasn't typedefed, you want to make sure to proceed the definition by `enum` keyword as enum cBool isTrue = false ;
30th Jun 2019, 2:40 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
+ 1
typedef int bool; #define true 1 #define false 0
30th Jun 2019, 3:58 PM
Vlad Serbu
Vlad Serbu - avatar