| stdbool.h |
| Name | stdbool.h |
| Author | ISO C Committee (WG14) |
| Released | 1999 |
| Operating system | Cross-platform |
| License | Varies by implementation |
stdbool.h
Overview
is a C header introduced to provide a dedicated Boolean type and related macros for the C programming language. It defines a Boolean type and symbolic constants intended to interoperate with C's existing integer model while aligning with standards from the International Organization for Standardization and implementations used by vendors such as Microsoft, GNU Project, Intel Corporation, ARM Limited, and IBM. The header's design responds to historical use of integers for truth values in projects like Unix utilities, compiler toolchains such as GCC, and portability layers in systems from FreeBSD and NetBSD to embedded stacks used by Arduino and TI ecosystems.
History and standardization
The introduction of traces to standardization work culminating in the ISO/IEC 9899:1999 standard, commonly cited as C99, produced by the ISO working group WG14 and influenced by proposals from members representing organizations like Bell Labs and Sun Microsystems. Debates during the C99 process invoked positions from figures and bodies tied to ANSI, the IEEE, and implementers including Richard Stallman's Free Software Foundation and corporate contributors from Microsoft Research and IBM Research. Adoption among compiler vendors such as GNU Compiler Collection, Clang (compiler), and proprietary compilers followed unevenly, with later convergence during the era of C11 and onward.
Contents and macros
The header defines a typedef and constant macros to standardize boolean usage across programs and libraries. It provides a typedef for the Boolean type compatible with C's integer promotions, a macro for the truth value 1 and the falsity value 0, and an implementation-defined representation compatible with existing integer operations in systems like POSIX-compliant environments and microcontroller SDKs from STMicroelectronics and NXP Semiconductors. Implementations typically expose: - a typedef for the Boolean type, - macros for truth and falsehood, - sometimes internal guards to avoid redefinition across headers used in projects such as OpenSSL, glibc, and musl libc.
Language semantics and usage
In C programs, the Boolean type from is intended to interoperate with control expressions, conditional statements, and logical operators used in codebases from Linux kernel-adjacent projects to application layers written for Windows and macOS. The semantics rely on the integer conversion rules described in the C standard: any nonzero integer converts to true while zero converts to false in contexts such as tests involving if statements, while loops, and logical operators used in algorithms influenced by collections in Boost (C++ libraries) and coding conventions promoted by standards bodies like ISO. Developers migrating code from legacy C idioms or integrating with foreign-language bindings such as Python extensions, Lua modules, or Rust FFI often map the header's Boolean type to corresponding types in those ecosystems to preserve value semantics and calling conventions.
Compatibility and portability
Portability considerations arise when integrating across diverse toolchains, embedded environments, and legacy source that predate C99. Projects maintained by organizations like The Apache Software Foundation, Mozilla Foundation, and Khronos Group commonly include conditional compatibility wrappers to support compilers lacking C99 headers or using nonstandard extensions from vendors such as Borland or TI compilers. For portability, many cross-platform frameworks and SDKs—examples include SDL (software), Qt (software), and LLVM-based toolchains—either assume the presence of or provide internal typedefs guarded by feature-detection macros to avoid conflicting definitions in environments like MinGW or proprietary embedded RTOSes used in Qualcomm-based platforms.
Implementations and examples
Common implementations of appear in standard libraries such as glibc, musl libc, Newlib, and platform SDKs bundled with compilers like GCC, Clang (compiler), and Microsoft Visual C++ toolchains (which historically provided different idioms). Typical example usage in a C source file shows inclusion of the header followed by Boolean variables and conditional logic used in networking stacks influenced by TCP/IP implementations, cryptographic code similar to that in OpenSSL, and device drivers seen in NetBSD and FreeBSD: - include the header, - declare Boolean variables, - use Boolean expressions in control flow and APIs exposed to foreign-language bindings.
For projects targeting legacy compilers or specialized toolchains from vendors such as IAR Systems and Green Hills Software, maintainers often provide compatibility shims modeled after widely deployed implementations to ensure consistent behavior across platforms and reuse in large-scale open-source ecosystems like Debian, Fedora, and OpenBSD.
Category:C (programming language)