Boolean Type

Our textbook uses a header file, bool.h, in many of the programs:
#ifndef BOOL_H
#define BOOL_H
typedef int Boolean;
const Boolean TRUE = 1;
const Boolean FALSE = 0;
#endif
There are 3 definitions contained within the file: These definitions allow us to use Boolean types as if they were part of the C++ language. The TRUE and FALSE constants are conveniences. Another way to define TRUE would be like this:
const Boolean TRUE = (1 == 1);
This allows us to guarantee that our programs will always react in the same way on all systems. You should always use TRUE in your programs, rather than the integer value assigned above:
Boolean b = someBoolFunc();

if (b == 1)        // bad idea
  doThis();

if (b == TRUE)     // good idea
  doThat();

if (b)             // good idea
  doOther();

Next page

Back to Lesson 2 Index
Back to Outline