After being pointed there by a compiler error, I noticed clang's stdbool.h file includes (among other things) the following lines:
#define bool bool
#define false false
#define true true
They're contained in an #ifdef block that enforces __cplusplus indirectly, hence the c++ tag even though stdbool.h is a C header.
What's the need for those defines? I imagine they're required for some preprocessor-related reason but I'd be interested to know what part of the standard or which technical reason makes it so clang has to include those.
stdbool.his a C header, not a C++ header. It is not usually found in C++ programs becausetrueandfalseare already keywords in C++.Consequently, if a C++ program includes
stdbool.hit 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++ supportsstdbool.hin C++ mode as a GNU extension, per the comments from the GCCstdbool.h:Clang, likewise, supports
stdbool.hin 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: