Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!brl-adm!brl-smoke!smoke!HARGED%ti-eg.csnet@CSNET-RELAY.ARPA From: HARGED%ti-eg.csnet@CSNET-RELAY.ARPA Newsgroups: net.lang.c Subject: More on BOOLEAN vs. boolean Message-ID: <559@brl-smoke.ARPA> Date: Mon, 5-May-86 17:46:23 EDT Article-I.D.: brl-smok.559 Posted: Mon May 5 17:46:23 1986 Date-Received: Thu, 8-May-86 07:09:51 EDT Sender: news@brl-smoke.ARPA Lines: 53 >(2) There isn't any ^^ (XOR) operator either, as in > if(divisor <0) ^^ (dividend <0) > quotient = -quotient; Periodically I encounter conditional expressions in the form ((a && !b) || (!a && b)) For those who remember their Karnaugh maps, that is equivalent to (a ^^ b) I normally grit my teeth and use "^", including a note specifying that the variables involved had *better* always be 1 or 0. >(3) There is no boolean data type. No big gripe; >lots of us say "typedef short bool" in our .h files. When I first started using C, I thought I would miss the boolean type. I'll have to admit that I haven't. With a (very) modest amount of discipline, a BOOLEAN can be typedef'ed, and all else remains the same. >o Multiple flag variables with local scope and no address operator (e.g. > variables declared "register bool") could be packed into a single word. *IF* packing bits is feasible on your host machine. (Whether you like it or not) there are many C implementations that can't afford the overhead of bit packing. >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(); }". I think the same problems with doing that now (on integers of whatever size) would plague the boolean type. The code that would have to generated to avoid giving a boolean variable an undefined value would probably match the size of the code currently generated when the user explicitly controls a flag's value. (x=true) and (x=false) for "set" and "clear" seem more than adequate. However, (~x) for "toggle" would be useful. The lack of an efficient toggle operation on integer BOOLEAN's is sometimes a pain. You are aware that the short-circuit evaluation rules associated with || and && actually make them shorthand forms for (a || b) <==> (a ? 1 : (b != 0)) (a && b) <==> (a ? (b != 0) : 0) which might have something to do with their not being included in the set of operators that can be combined with the assignment operator. Richard Hargrove csnet: harged@ti-eg Texas Instruments, Inc arpa : harged%ti-eg@csnet-relay.arpa ---------------------- ------------------------------------