Putting aside the fact that since c99 the stdbool.h has existed, when defining macros to handle Boolean types in C
is there any difference between the following
They are just same.
!0
is 1
so !FALSE
is 1
#define TRUE !FALSE
has no technical benefit at all although it existed for along time and appeared many where.
#define TRUE !FALSE
can be misunderstood, one could think that TRUE
represents every value which not 0
.
1
equals to TRUE
, others values like 2
,3
, 255
... (which !=0
) does not equal to TRUE
To prevent this misunderstanding, many organizations require not using #define TRUE !FALSE
any more or comparison to TRUE
should be changed to !FALSE
:
// Should not
if (var_bool == TRUE) {
...
}
//Should
if (var_bool != FALSE) {
...
}