Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is stdbool.h?

Tags:

I want to find the _Bool definition on my system, so for systems where it's missing I can implement it. I've seen various definitions for it here and on other sites, but wanted to check on the system for the definitive definition.

Slight problem, in that I can't find where _Bool is defined or even stdbool.h

mussys@debmus:~$ find /usr/include/* -name stdbool.h /usr/include/c++/4.3/tr1/stdbool.h 

And grep for _Bool on /usr/include/* and /usr/include/*/* does not find it either.

So where is it?

like image 932
James Morris Avatar asked Nov 01 '09 10:11

James Morris


People also ask

What is #include Stdbool H?

Using the system header file stdbool. h allows you to use bool as a Boolean data type. true evaluates to 1 and false evaluates to 0 .

Should I use Stdbool H?

h was added to allow users the obvious name. That way, if your code didn't have a home-brewed bool , you could use the built in one. So do indeed use stdbool. h if you aren't bound to some existing home-brewed bool .

Where is _Bool defined?

The _Bool type is a new type appearing in the standard C99. It is an unsigned integer type. Its range of values it has to be able to hold the values 0 and 1. The range of values of _Bool is contained in the range of values of any other unsigned integer type.

What C library has bool?

The C programming language, as of C99, supports Boolean arithmetic with the built-in type _Bool (see _Bool). When the header <stdbool. h> is included, the Boolean type is also accessible as bool .


1 Answers

_Bool is a built-in type, so don't expect to find a definition for it in a header file, even a system header file.

Having said that, guessing your system from the paths that you are searching, have you looked in /usr/lib/gcc/*/*/include ?

My "real" stdbool.h lives there. As expected it #defines bool to be _Bool. As _Bool is a type native to the compiler there's no definition for it in the header file.

like image 154
CB Bailey Avatar answered Oct 13 '22 20:10

CB Bailey