4

There are many questions of this kind on SO so I apologize for this additional one.

stdbool.h defines this:

#define true  (1)
#define false (0)

However I've seen many other declarations in bad code such as

#define true  (0xFF)
#define false (!true)

Or even worse

#define true  (0xAAAAAAAA)
#define false (~true)

In a real context we could imagine a variable int istrue used somewhere in a bad C program:

istrue = 1;

Because the code I am looking at is pretty ugly, I cannot assume I won't see things like:

if (istrue == 1)

That will make me refrain from replacing istrue = 1 with istrue = true.

So my question is:

In C, is true always equal to 1 and false always equal to 0 for any C compiler, and should this assumption always be valid in any case?

jwodder
  • 54,758
  • 12
  • 108
  • 124
nowox
  • 25,978
  • 39
  • 143
  • 293

0 Answers0