C boolean type is not defined in standard C language before C99. the option 3) is my choice.
Option 1 typedef int bool; #define true 1 #define false 0 Option 2 typedef int bool; enum { false, true }; Option 3 typedef enum { false, true } bool; Option 4 (C99) #include <stdbool.h> Explanation Options 1, 2 and 3 will have in practice the same identical behavior. #2 and #3 don't use #defines though, which in my opinion is better. Option 4 will work only if you use C99 and it's the "standard way" to do it. Choose this if possible. If you are undecided, go with #3!
- Using boolean values in C
- Use of bool in C
- Boolean Values
- True and False in C
- 3.3 Boolean Expressions
- Boolean type support library
No comments:
Post a Comment