Defining a bool type using typedef

suggest change

Considering that most debuggers are not aware of #define macros, but can check enum constants, it may be desirable to do something like this:

#if __STDC_VERSION__ < 199900L
typedef enum { false, true } bool;
/* Modern C code might expect these to be macros. */
# ifndef bool
#  define bool bool
# endif
# ifndef true
#  define true true
# endif
# ifndef false
#  define false false
# endif
# include <stdbool.h>

/* Somewhere later in the code ... */
bool b = true;

This allows compilers for historic versions of C to function, but remains forward compatible if the code is compiled with a modern C compiler.

For more information on typedef, see, for more on enum see

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents