darren@revcan.UUCP (Darren Morbey) (04/10/91)
Pardon me for interrupting (I started this whole thing in the first place) but I've gotten a lot of email and posted articles about the bitwise xor. Unfortunately, our system has been down for several days, so the article I planned to post, including your comments and suggestions, will need _major_ rewriting to accomodate all comments. I _will_ post some of the comments I have recieved as well as other macros. Thanks to you all for sending. I believe my request should be revised, however, regarding some of the points made in these articles. In light of them, I revise what I require here: I would like to "simulate" ^^ i.e if( a ^^ b ) with a macro thus: #define XOR(A,B) ... The macro should accept all numeric types for A and B, treating them as "0" or "non-0" as && and ||. If a macro is supplied, each operand must be evaluated O&OO (once and only once.) There are some things I knew and that I didn't know that I would like to make clear that I know them now. They are as follows: I KNEW there is no short-circuit evaluation for XOR as there is for && and ||. I want to guarantee that they are both executed anyway. I DIDN'T KNOW && and || short circuited. I DIDN'T KNOW !(a) is always an int. I DIDN'T KNOW A?B:C means only one of B and C are evaluated. I JUST REALIZED for certain A and B, my #1 could execute A _twice_ and B _not_ _at_ _all!_ I DID KNOW that #1 is unsatisfactory. It was put on as a general idea. Please no more about it, but I do challenge anyone who can figure out how my last statement is possible. I will post the answer later. Other than that, please don't flog my dead horse. :-) Thank you again for your comments. It will take a while to summarize everything I have recieved. Until then, happy programming. [ Darren Morby +1 613 957 9281 {uunet|lsuc|fts1}!revcan!darren ] [ Revenue Canada Taxation, 3052-400 Cumberland St, Ottawa,ONT K1A 0L8 ] [ "The challenge... is yours." -Dick Clark ]
darren@revcan.UUCP (Darren Morbey) (04/25/91)
I left as an exercise on making #define XOR(A,B) ( (!(A)&&(B)) || ((A)&&!(B)) ) execute A twice and B no times (and B twice.) The only respondent correctly identified this as operands with side effects. In this case, XOR(++x,b) executes B: no times if x is initially -2. twice if x is initially -1. The prize goes to Ian Collier (Ian.Collier@prg.ox.ac.uk) for submitting something like this (and being the only one to do so.) As I was reviewing some of the responses and followup articles to the logical XOR question, I came across a pretty good argument for not having ^^. This article comes from a "Dan," who says "since you "can always implement a non-short-circuit logical operator, there's no "reason for the language to provide any logical operators other than "the short-circuit ones." Due to the end of my co-operative work term on Friday, I'm unable to accept any responses anymore. :-( I may be able to get back on in university ( I don't know though ). I would like to thank all of you for listening and responding to my question. [ Darren Morby +1 613 957 9281 {uunet|lsuc|fts1}!revcan!darren ] [ Revenue Canada Taxation, 3052-400 Cumberland St, Ottawa,ONT K1A 0L8 ]