Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!zaphod.mps.ohio-state.edu!samsung!umich!sharkey!amara!mcdaniel From: mcdaniel@amara.uucp (Tim McDaniel) Newsgroups: comp.lang.c Subject: Re: Brain Teaser Message-ID: Date: 28 Mar 90 01:01:11 GMT References: <10289@wpi.wpi.edu> Sender: news@amara.UUCP Organization: Applied Dynamics Int'l. Lines: 25 In-reply-to: oesterle@wpi.wpi.edu's message of 27 Mar 90 18:23:30 GMT oesterle@wpi.wpi.edu (Shawn H. Oesterle) asks how to swap two pointers without using a third pointer. Swap-macros-that-use-no-intermediate-variables appear in comp.lang.c every so often. They usually use exclusive-OR, and hence only work for integral types. Oesterle's Variant, x += y; y = x - y; x -= y; can fail if an intermediate expression overflows. You can't do portably swap arbitrary legal pointer values without using an intermediate variable. In short, "no". (I've never had a problem scrounging data space for an intermediate value, and I *never* want to burn the extra CPU time or risk overflow. If this discussion is fresh and interesting to you, I'm glad, and you have a perfect right to discuss it in comp.lang.c all you want. But I'm sorry to tell you I'm an old sourpuss, and I'm afraid that this subject is going into my KILL file immediately.) -- Tim McDaniel Applied Dynamics International, Ann Arbor, MI Internet: mcdaniel%amara.uucp@mailgw.cc.umich.edu UUCP: {uunet,sharkey}!amara!mcdaniel