TRUE and FALSE

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Wed Sep 5 15:16:23 AEST 1990


In article <5398 at harrier.ukc.ac.uk> mtr at ukc.ac.uk (M.T.Russell) writes:
> To the people complaining about `if (x == TRUE)': YOU ONLY USE `TRUE' AND
> `FALSE' FOR ASSIGNMENT AND PARAMETER PASSING.  It's a fairly simple rule.

It is wise to take advantage of the language's syntax to remind the
programmer of this at every turn. If I were really desperate for this
type:

typedef struct { int truth; } truefalse;
#define set_true(b) ((void) ((b)->true = 1))
#define set_false(b) ((void) ((b)->true = 0))
#define is_true(b) ((b).true)

Usage: truefalse flagfoo; set_true(&flagfoo); if (is_true(flagfoo)) ...

Somehow in real programs I've never had trouble with declaring variables
flagthis, flagthat, flagtheotherthing. The ``flag'' alerts the reader.
Flags are multi-valued when I need to express different shades of truth.

---Dan



More information about the Comp.lang.c mailing list