Boolean Operators Slighted in C

KW Heuer kwh at bentley.UUCP
Tue May 6 23:44:24 AEST 1986


In article <12329 at ucla-cs.ARPA> jimc at ucla-cs.ARPA (Jim Carter) writes:
>In article <778 at bentley.UUCP> kwh at bentley.UUCP (KW Heuer) writes:
>>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,

Whoa!  The operator I was referring to was "v = v < e", which is the clear
generalization of "op=" on operator "<".  This is meaningful in C, because
the boolean result of "<" will be interpreted as an integer.  But it is not
generally useful, because one does not normally use a boolean argument to a
comparison operator like "<".

>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;

Now we're discussing "if (v < e) v = e;" which means "v = max(v,e);".  This
is indeed a useful operation, but the operator is now "max" rather than "<".

>Now "<=" already means something else so this syntax is not acceptable.
>How about "v < = e" with a mandatory blank?  This is atrocious human
>engineering but at least is parseable.  Anybody have any better ideas?

Yes.  I already mentioned this in the discussion about builtins, but I think
it bears repeating.

Introduce a new operator "<>" for max (and "><" for min).
Add the corresponding assignment operator "<>=" (and "><=") with the above
meaning.

The symbol "<>" is currently meaningless in C, though basic and pascal users
would have a fit.  "|>" and "<|" may be better choices.  "\/" and "/\" would
mimic the mathematical notation, but there may be reasons to avoid the use
of backslash in program source.

Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint



More information about the Comp.lang.c mailing list