Site Tools


stdbool.h

Table of Contents

<stdbool.h>

In C programming language, <stdbool.h> is a header that's part of C standard library. It defines a boolean type bool as well as constants true and false.

You need at least version C99 to use this header, so compile with gcc -std=c99 main.c -o program.

Traditionally, C does not support boolean types. You just used int type instead, or any other integral type. Practically any value equivalent to the value zero (NULL, 0, 0.0f, '\0') is considered “false”. Otherwise the value is considered “true”.

In C99, the commitee introduced a keyword _Bool. The reason they didn't name it bool is because that would break the backward compatibility of C++ with C and C++ was an already mature language in 1999. The <stdbool.h> header is then offered if you want to use bool, true and false and don't want them to clash with C++ or define them yourself.

But this header is now deprecated in C23.

The following is a simplified implementation of <stdbool.h> header:

#ifndef __STDBOOL_H__
#define __STDBOOL_H__
 
#if __cplusplus
/* you already have bool, true, false thanks to C++! */
/* but C++ doesn't have _Bool so let's define it*/
#define _Bool bool
#else
#define bool _Bool
#define true 1
#define false 0
#endif
#define __bool_true_false_are_defined 1
#endif

The <stdbool.h> header is part of the compiler toolchain for the target architecture.

For GNU GCC 15.2.1 targeting x86_64 architecture, the likely path is the following:

 $ file /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/include/stdbool.h
stdbool.h: C source, ASCII text
stdbool.h.txt · Last modified: (external edit)