What I'd really like to see in an if-statement...

Alan J Rosenthal flaps at gpu.utcs.utoronto.ca
Sat Aug 12 22:24:41 AEST 1989


People seem to be wondering what use operators such as `<' have as applied to
boolean-valued operands.  For example, would (a < b < c) always be a mistake?
In fact, it would not, and I would like to point out the meaning of relational
operators as applied to boolean-valued operands.

If `a' and `b' are boolean-valued values (i.e. normalized, i.e. `!!' is the
boolean normalize operator in C), then `a < b' means "a is weaker than b", in
other words `a' is false and `b' is true.  `a <= b' means "a implies b".

Similarly the other boolean-valued operators in C can be used on boolean
values.  Another example:  `!=' means xor, and so (a != b != c) is the parity
of the three bits a, b, and c.

[ Followup avoidance tactics: I know that there is no boolean type in C, and
that relational operators return ints.  In fact, if I did not know this, I
would not have come up with the above. ]



More information about the Comp.lang.c mailing list