+ 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
5 Antworten
+ 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
+ 1
I tried this and it doesn't work
https://code.sololearn.com/cfWDEx15QtLH/?ref=app
+ 1
I don't need use booleans yet!
I just want to implement them on my own for educational purposes
+ 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 ;
+ 1
typedef int bool;
#define true 1
#define false 0