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
#else
# include <stdbool.h>
#endif
/* 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 Typedef, for more on enum
see Enumerations