My linux gcc compiler does not support booleans

I am trying to make a function with return type as boolean ... the program syntax seems correct, but the compiler gives errors ....

Header files that I included:

#include<stdio.h>
#include<stdlib.h>

function created by me:

34.bool checknull(struct node* node){
35.    if ( node != NULL )
36.        return TRUE;
37.       
38.    return false;
39.}

and what I get at compile time

bininsertion.c:34:1: error: unknown type name ‘bool’
bininsertion.c: In function ‘checknull’:
bininsertion.c:36:10: error: ‘TRUE’ undeclared (first use in this function)
bininsertion.c:36:10: note: each undeclared identifier is reported only once for each  function it appears in
bininsertion.c:38:9: error: ‘false’ undeclared (first use in this function)

I tried "TRUE, false" in both capital and lowercase letters, but it doesn't seem to work ...

+5
source share
3 answers

You must enable <stdbool.h>, if you want bool, trueand false. Also he true, not true.


If you do not want to include stdbool.h, you can just use a little ugly _Bool.

+18
source

bool .
Visual Studio.. Microsoft- ..
stdbool.h, :)

-1

Original answer

Try turning on cstdio and cstdlib. It doesn’t matter, but I also noticed these strange errors with my compiler. Things that used to work no longer work

Edit

In C, false is represented as 0, and truth is something non-zero.

In essence, you can roll your own data type boollike this

typedef enum {false, true} bool;

Then you can use it in the same way as in your application.

You can also include stdbool.h, which should have something similar to a listing clause.

-2
source

All Articles