Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: Boolean Operators Slighted in C Message-ID: <2692@utcsri.UUCP> Date: Sat, 3-May-86 12:39:13 EDT Article-I.D.: utcsri.2692 Posted: Sat May 3 12:39:13 1986 Date-Received: Sat, 3-May-86 13:24:48 EDT References: <838@ihwpt.UUCP> <778@bentley.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 44 Summary: In article <778@bentley.UUCP> kwh@bentley.UUCP (KW Heuer) writes: >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". > Interesting - I was going to suggest if(e)v=1; but that's not the same thing. I was surprised to find out recently that ` i >> = 1 ' is legal, as opposed to `>>='. I really think this should produce at least a warning. (4.2BSD) > >>(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.) If I had $0.02 for everything that people have said should be done by a smart compiler... :-) :-) I know, that's what compilers are for. But it's not quite the same thing. 2 ^^ 1 should be 0, and 2!=1 is 1, and 2^1 is 3. Of course, in the example given, that won't happen. In any case, you can always say !a != !b. On the subject of operators, someone said a while back that they had a compiler with commented-out code to support '/\' and '\/' ( max and min ) operators - and that they had qualms about activating it and then writing non-portable code. I suggest that they activate it, and then write #define min(a,b) ((a)\/(b)) #define max(a,b) ((a)/\(b)) in a header, to allow portability. Presumably, the code produced by these operators should be somewhat better than a>b?a:b. Of course, you still have to avoid writing min( array[atoi(x1)], i+cindex[getc(file)]) :-). -- "For every action there is an equal and opposite malfunction" ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg