My linux's gcc compiler not supporting boolean values
17,092
You should include <stdbool.h>
if you want bool
, true
and false
. Also it's true
, not TRUE
.
If you don't want to include stdbool.h
you can just use the slightly ugly _Bool
.
Author by
Sabre.Tooth
Updated on June 24, 2022Comments
-
Sabre.Tooth almost 2 years
I'm trying to make a function with return type as boolean...the syntax of the program seems to be correct but the compiler is giving errors....
The header files I've included are:
#include<stdio.h> #include<stdlib.h>
the function I've created is:
34.bool checknull(struct node* node){ 35. if ( node != NULL ) 36. return TRUE; 37. 38. return false; 39.}
and what I'm getting at compile time is
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've tried "TRUE,false" both in small and capital letters but doesn't seem to work...
-
Sabre.Tooth about 11 yearsincluding stdbool.h solves my problem...thanx for that...and can you please explain the slightly ugly part i.e. how to use "_Bool" ( Syntax and an example )...
-
cnicutar about 11 years@Sabre.Tooth Use it like a normal type. So wherever you would write
bool
you could also write_Bool
. The fact is_Bool
is the "real" type, introduced in C99 andbool
is just an alias. They couldn't introducebool
since it wasn't a reserved keyword in previous standards so it would have broken programs already using it. -
Sabre.Tooth about 11 yearsusing _Bool I still have to include stdbool.h because compiler treats "true" and "false" as undeclared variables...thnxxx for the help...
-
cnicutar about 11 years@Sabre.Tooth Yeah, or you can use
1
and0
. But by all means, I recommendstdbool.h
. -
geekybedouin about 11 yearsaha.. I just made some search.. bool is a datatype in C++.. :) the edit button isn't workin though..