You can get rid of the #defines by using an enum:
Code:
typedef enum {TRUE=1, FALSE=0} bool;
There's also a small practical benefit for this approach:
Some compilers will be able to do some extra type-checking against the enum values, and warn you if you accidentily try to do something like "bool b_Var = 5".
Quote:
|
Originally Posted by Joe Ross
There is no boolean variable type in C. Most people declare it as char (or unsigned char) and use the value 0 for false and 1 (or any value != 0) for true.
Through the use of #defines and typedefs, you can emulate it, though.
Code:
typedef unsigned char bool
#define TRUE 1
#define FALSE 0
Then just use the variable type bool and the values TRUE and FALSE.
|