Boolean Operators Slighted in C
Wayne Throop
throopw at dg_rtp.UUCP
Fri May 9 06:36:34 AEST 1986
> jimc at ucla-cs.ARPA (Jim Carter)
>> kwh at bentley.UUCP (KW Heuer)
>>Btw, you can't have *all* operators extended with "=". How would you write
>>"v = v < e;"? (Not that it's useful.)
> I think it's useful! As written, of course, it's semantically invalid,
> but what you really mean is "v <= e" (sic) or, to demonstrate where it's
> really useful,
> array[horrendous] [subscript] [list] <= bigexpr;
> rather than
> if (array[h][s][l] < bigexpr) array[h][s][l] = bigexpr;
The point is not that it isn't useful to collapse multiple array (or
other clumsy) references. The point is that in "e1 = e1 < e2", the "<"
operator assumes arguments with numeric semantics and yeilds a value
with boolean semantics. Since e1 is both an argument and a result, this
expression isn't very meaningful. The fact that C overloads the numeric
types with boolean meaning doesn't make this a useful thing to do.
Interestingly, if e2 also has boolean semantics, the "e1 < e2" gives the
same result as "!e1 && e2" (ignoring side effects). Doesn't seem like a
primitive to clammor for in the language, nor does "<" seem like a good
symbol for it if it were a primitive.
Now, I know what all you hackers are saying. You're saying "But Wayne,
how did you become a LOVE GOD?" (What's that? net.lang.c? Not
net.panting.singles? Sorry, I mean) "But Wayne, I just don't care
diddly about numeric vs boolean type safety debates. I just want
something that'll WORK." Ok. Fine. But you'll probably be looking for
subtle and disgusting bugs in programs that contain oddities like
"e1 = e1 < e2" long after others are happily using working programs that
don't. So there.
--
Wayne Throop <the-known-world>!mcnc!rti-sel!dg_rtp!throopw
More information about the Comp.lang.c
mailing list