true and false in C

All along I've been using the true and false statements in both C(and C++), thinking they are part of the core language(I still love to think they are). I recently entered microcontroller programming, specifically programming Atmel AVRMega microcontrollers, using Atmel Studio 7, and I noticed that while programming in C, unless I explicitly #define true 1 and #define false 0 , the compiler does not detect true and false as keywords, and hence flags them as errors.

My question is are those 'keywords' part of C or/and C++?
Last edited on
For C, no: http://en.cppreference.com/w/c/keyword

IIRC, older C standards didn't have any support for boolean types, but newer C standards have support in the standard library. Even then, they are not keywords, so as to retain compatibility with existing code.

For C++, they are keywords.
Last edited on
closed account (E0p9LyTq)
Since C99 there has been support of a sort for boolean values, you just include the <stdbool.h> header file.

http://www.cplusplus.com/reference/cstdbool/

http://en.cppreference.com/w/c/types/boolean
The type "bool" should also not be defined unless you include stdbool.h. C uses the keyword _Bool. Check out this header for an implementation of stdbool.h: http://clang.llvm.org/doxygen/stdbool_8h_source.html
Thanks
Topic archived. No new replies allowed.