Why does clang’s stdbool.h contain #define false false

stdbool.h is a C header, not a C++ header. It is not usually found in C++ programs because true and false are already keywords in C++.

Consequently, if a C++ program includes stdbool.h it is a fairly clear indication that it is a ported-over C program (e.g. a C program that is being compiled as C++). In this case, G++ supports stdbool.h in C++ mode as a GNU extension, per the comments from the GCC stdbool.h:

/* Supporting <stdbool.h> in C++ is a GCC extension.  */
#define _Bool        bool
#define bool        bool
#define false        false
#define true        true

...

/* Signal that all the definitions are present.  */
#define __bool_true_false_are_defined        1

Clang, likewise, supports stdbool.h in C++ for compatibility with G++.
The values are intentionally defined here to match the built-in C++ type rather than the traditional C99 definitions. They are defined as macros presumably to provide some compatibility with the C99 standard, which requires:

The header shall define the following macros: bool, true, false, __bool_true_false_are_defined.

An application may undefine and then possibly redefine the macros bool, true, and false.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)