Is bool a native C type?

asussex picture asussex · Oct 22, 2009 · Viewed 332.4k times · Source

I've noticed that the Linux kernel code uses bool, but I thought that bool was a C++ type. Is bool a standard C extension (e.g., ISO C90) or a GCC extension?

Answer

AnT picture AnT · Oct 22, 2009

bool exists in the current C - C99, but not in C89/90.

In C99 the native type is actually called _Bool, while bool is a standard library macro defined in stdbool.h (which expectedly resolves to _Bool). Objects of type _Bool hold either 0 or 1, while true and false are also macros from stdbool.h.

Note, BTW, that this implies that C preprocessor will interpret #if true as #if 0 unless stdbool.h is included. Meanwhile, C++ preprocessor is required to natively recognize true as a language literal.