Since the new C standard, C99, was ratified, there is a new boolean data type, _Bool, which is only capable of holding the values 0 and 1. If you include the header <stdbool.h>, you bring into scope a macro, bool, which expands to _Bool.
So, you can either not include <stdbool.h> and declare boolean data types like this:
_Bool my_bool;
Or:
#include <stdbool.h>
/* ... */
bool my_bool;
It think the idea of having _Bool and requiring the <stdbool.h> header if the programmer wants to use bool is because there's a whole lot of existing code that uses bool in typedefs like this:
typedef unsigned char bool; /* or int or whatever */
And using "bool" as a new data type would break all that code.
Since there are no compilers claiming C99 conformance yet, your compiler may or may not support this. The <stdbool.h> header also brings the constants true and false into scope which are equal to 1 and 0 respectively.
As has been said above, you can define your own constants, but be careful! Particularly if you want your constants to be equivalent to the way C regards true and false: all non-zero values are true (not just 1) and a zero value is false. The problem is, you can't do it with defines.
Say, you defined them as abp suggested:
#define TRUE 1
#define FALSE 0
Then later in your code, you'll be making comparisons with your TRUE, FALSE types like this:
unsigned char a;
/* put something in a */
if (a==TRUE) {
/* it is true! */
But, unless a==1, the test will fail, giving unexpected results if a is some other non-zero value which is supposed to indicate "true".
Even this doesn't work:
#define FALSE 0
#define TRUE !FALSE
Still, TRUE evaluates to 1.
With the new _Bool type, if you assign a non-zero value to it, the value 1 will actually get assigned to the variable. You can do stuff like this with no problem:
#include <stdbool.h>
/* ... */
bool foo=5; /* foo actually gets assigned 1 */
if (foo==true) {
/* ok! */
One pre-C99 way is with parameterized macros:
#define FALSE

==0
#define TRUE

!=0
Then in your tests:
if (TRUE(a)) {
/* it's true */
Personally, I think this is all a waste of time (I'm not even sure if I'll use the C99 bool type). I much prefer this:
unsigned char a;
/* ... */
if (a) {
/* it's true */
/* ... */
if (!a) {
/* it's false */
Russ
bobbitts@hotmail.com