Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!caip!brl-adm!brl-smoke!smoke!rbj@icst-cmr From: rbj@icst-cmr (Root Boy Jim) Newsgroups: net.lang.c Subject: Re: swap() macro Message-ID: <1941@brl-smoke.ARPA> Date: Thu, 3-Jul-86 15:36:58 EDT Article-I.D.: brl-smok.1941 Posted: Thu Jul 3 15:36:58 1986 Date-Received: Sat, 5-Jul-86 05:55:15 EDT Sender: news@brl-smoke.ARPA Lines: 46 In article <2225@umcp-cs.UUCP> I replied: >I have here a C program that effects call-by-name and does >indeed perform a swap: What I failed to consider, of course, is the classic problem with call by name: arrays. Watch what happens when I `swap' `i' and `a[i]', using an expanded form of the swap function (this is necessary to avoid compiler dependencies in this particular case). Okay, so at least Chris and I are talking about the same thing. Ah well, at least I caught my error myself. . . . Ah, but why not fix it too? Who says you have to evaluate f1 & f2 each time you reference them? swap(f1, f2) swap(f1, f2) int *(*f1)(), *(*f2)(); int *(*f1)(), *(*f2)(); { { int t1, t2; int t1, t2, *a1, *a2; t1 = *(*f1)(); t1 = *(a1 = (*f1)()); t2 = *(*f2)(); t2 = *(a2 = (*f2)()); *(*f1)() = t2; *a1 = t2; *(*f2)() = t1; *a2 = t1; } } By definition you say? Whaddya want, swapping or call by name? To the outside world, swap is atomic, so who cares what happens inside? This way, t2 is unneeded as well. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu Now recite with me the Hacker's Prayer: Our father, UART in heaven, Hallowed Call by Name ... (Root Boy) Jim Cottrell OMNIVERSAL AWARENESS?? Oh, YEH!! First you need 4 GALLONS of JELL-O and a BIG WRENCH!!... I think you drop th'WRENCH in the JELL-O as if it was a FLAVOR, or an INGREDIENT... ...or...I...um...WHERE'S the WASHING MACHINES?