Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My linux's gcc compiler not supporting boolean values [duplicate]

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...

like image 685
Sabre.Tooth Avatar asked Mar 03 '13 08:03

Sabre.Tooth


People also ask

Why is there no bool in c?

C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.

What can I use instead of boolean in c?

Though C doesn't support Boolean value. But we can use Logical Operators like '&&', '||' or '!

When did bool add c?

An introduction to how to use booleans in C C99, the version of C released in 1999/2000, introduced a boolean type. To use it, however, you need to import a header file, so I'm not sure we can technically call it “native”.

Is bool part of STD?

an appropriate answer to this is, yes a C standard such as C90, specifically the C99 standard, does implement a bool type.


1 Answers

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.

like image 109
cnicutar Avatar answered Oct 11 '22 11:10

cnicutar