Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.lang.c Subject: Re: macros and semicolons Message-ID: <20970@crdgw1.crd.ge.com> Date: 27 Jun 91 21:40:16 GMT References: <1991Jun24.213932.595@otago.ac.nz> <1991Jun24.144701.8479@world.std.com> <160662@pyramid.pyramid.com> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Lines: 22 In article <160662@pyramid.pyramid.com>, markhall@pyrps5.pyramid.com (Mark Hall) writes: |>> |>>#define SWAP(a, b) {int c; c = a; a = b; b = c} |> |>Forgive me for this unsufferable horn-tooting; I just couldn't resist |>(I also couldn't believe no one else sent this reply :-). . . . |> |>NO macro will work for a swap. You suffer from the call-by-name rule |>which undid ALGOL in this case. Consider the expansion of SWAP(i,a[i]): |> |> int c; c = i; i = a[i]; a[i] = c; #define SWAP(a,b) {int c, *pa=&(a), *pb=&(b); c=*pa; *pa=*pb; *pb=c;} This doesn't solve all problems, but it gets the one you mentioned. I think. :-) ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com