Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c Subject: Re: Boolean Operators Slighted in C Message-ID: <778@bentley.UUCP> Date: Wed, 30-Apr-86 15:44:37 EDT Article-I.D.: bentley.778 Posted: Wed Apr 30 15:44:37 1986 Date-Received: Fri, 2-May-86 23:52:26 EDT References: <838@ihwpt.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 35 In article <838@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