Why #define TRUE (1==1) in a C boolean macro instead of simply as 1?

user2468316 picture user2468316 · Jun 9, 2013 · Viewed 23.2k times · Source

I've seen definitions in C

#define TRUE (1==1)
#define FALSE (!TRUE)

Is this necessary? What's the benefit over simply defining TRUE as 1, and FALSE as 0?

Answer

SLaks picture SLaks · Jun 9, 2013

This approach will use the actual boolean type (and resolve to true and false) if the compiler supports it. (specifically, C++)

However, it would be better to check whether C++ is in use (via the __cplusplus macro) and actually use true and false.

In a C compiler, this is equivalent to 0 and 1.
(note that removing the parentheses will break that due to order of operations)