Path: utzoo!attcan!utgpu!flaps
From: flaps@gpu.utcs.utoronto.ca (Alan J Rosenthal)
Newsgroups: comp.lang.c
Subject: Re: What I'd really like to see in an if-statement...
Message-ID: <1989Aug12.082441.2468@gpu.utcs.utoronto.ca>
Date: 12 Aug 89 12:24:41 GMT
References: <5024@alvin.mcnc.org> <1300@atanasoff.cs.iastate.edu> <456@helios.prosys.se> <14521@bfmny0.UUCP> <1864@salgado.Solbourne.COM> <14522@bfmny0.UUCP> <5040@alvin.mcnc.org>
Organization: University of Toronto
Lines: 17
Checksum: 46828


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. ]