Boolean Operators Slighted in C

KW Heuer kwh at bentley.UUCP
Thu May 1 05:44:37 AEST 1986


In article <838 at ihwpt.UUCP> ihwpt!knudsen writes:
>(1) Found out this weekend that you can't say:
>	boolvar ||= boolean_expression

An interesting expression.  The left side of the assignment would have to be
evaluated first, and if already set, do nothing.  I presume the reason this is
omitted is because it's normally written "if (v || e) v=1;" or "if (!v && e)
v=1;" rather than "v = v || e".

Btw, you can't have *all* operators extended with "=".  How would you write
"v = v < e;"?  (Not that it's useful.)

>(2) There isn't any ^^ (XOR) operator either, as in
>	if(divisor <0) ^^ (dividend <0)
>		quotient = -quotient;

There is, but it's spelled "!=".  (Presumably more efficient than "^", though
I think either one should work with a smart compiler.)

>(3) There is no boolean data type.  No big gripe;
>lots of us say "typedef short bool" in our .h files.

I'd assume either "char" (for space) or "int" (for time).  "short" probably
gives you the worst of both worlds.

However, a true boolean datatype would have a couple of advantages:

o  Multiple flag variables with local scope and no address operator (e.g.
   variables declared "register bool") could be packed into a single word.

o  "++x" and "--x" could be defined as "set" and "clear"; "x++" and "x--"
   would then be "test and (set|clear)".  This would obviate such things as
   "if (!flag) { flag=1; printmsg(); }".

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



More information about the Comp.lang.c mailing list