Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

_Bool is a built-in unsigned integer type introduced in the C99 standard, designed specifically to represent boolean truth values. Unlike standard integer types, _Bool enforces strict boolean semantics at the language level: it is only capable of storing the values 0 or 1.

Syntax and Implicit Conversion

The most defining characteristic of _Bool is its implicit conversion rules. When any scalar value (integer, floating-point, or pointer) is assigned to a _Bool variable, the compiler automatically normalizes the value. Any non-zero value or non-null pointer evaluates to 1, while a zero value or null pointer evaluates to 0.
_Bool flag_zero  = 0;       // Stores 0
_Bool flag_one   = 1;       // Stores 1

// Implicit conversion examples
_Bool flag_int   = 42;      // Evaluates to 1
_Bool flag_neg   = -99;     // Evaluates to 1
_Bool flag_float = 0.001f;  // Evaluates to 1
_Bool flag_null  = '\0';    // Evaluates to 0

int* ptr = 0;               // Null pointer
_Bool flag_ptr   = ptr;     // Evaluates to 0
This behavior prevents overflow issues that occur when using standard int or char types for boolean logic, where assigning a value like 256 to an 8-bit integer might truncate to 0.

Memory Representation

The C standard dictates that _Bool must be large enough to store the values 0 and 1. While the exact memory footprint is implementation-defined, sizeof(_Bool) is typically 1 byte (8 bits) on modern architectures. This is because 1 byte is the smallest individually addressable unit of memory for most CPUs.
#include <stdio.h>

int main(void) {
    // Typically outputs: Size of _Bool: 1 byte(s)
    printf("Size of _Bool: %zu byte(s)\n", sizeof(_Bool)); 
    return 0;
}

The <stdbool.h> Abstraction

While _Bool is the native language keyword, C99 also introduced the <stdbool.h> header to provide a more conventional syntax that aligns with C++ and other modern languages. This header defines three macros that map directly to the _Bool type and its binary states.
#include <stdbool.h>

/* 
Underlying macro definitions in <stdbool.h>:
#define bool  _Bool
#define true  1
#define false 0
*/

bool is_ready = true;
bool is_done  = false;

Integer Promotion

Because _Bool is classified as an integer type, it is subject to standard integer promotion rules. When a _Bool is used in an arithmetic expression, it is promoted to an int before the operation is evaluated.
_Bool a = 1;
_Bool b = 1;

// 'a' and 'b' are promoted to int (1 + 1). 
// The result is 2, which is stored in 'result'.
int result = a + b; 

// If assigned back to a _Bool, the result (2) is implicitly converted back to 1.
_Bool combined = a + b; 
Master C with Deep Grasping Methodology!Learn More