Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!cmcl2!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: net.lang.c Subject: Re: SWAP macro Message-ID: <454@mcgill-vision.UUCP> Date: Sat, 12-Jul-86 03:10:01 EDT Article-I.D.: mcgill-v.454 Posted: Sat Jul 12 03:10:01 1986 Date-Received: Sun, 13-Jul-86 07:00:46 EDT References: <857@bu-cs.UUCP> Organization: McGill University, Montreal Lines: 39 In article <857@bu-cs.UUCP>, bzs@bu-cs.UUCP (Barry Shein) writes: > And then again, there's always [...] > > #define swap(x,y,t) { \ > t *p1 = &(x), *p2 = &(y), tmp; \ > \ [...swap code...] > Also, pointer types would have to be typedef'd to be useful as > swap(x,y,char *) would not quite work (but w/ a typedef it works > fine.) Because you wrote the declaration carelessly. Should work fine if you write it as { \ t *p1 = &(x); t *p2 = &(y); t tmp; (assuming there are no side-effects in the type argument :-). See, now *I* always write declarations one declaration per variable, even writing int i; int j; instead of int i,j; This sort of thing is where the habit pays off (preen preen :-). Now you *still* need a typedef when the type involves arrays or functions (such as a pointer to function, a reasonable thing to want to exchange). I suspect there is no way around this, anyone care to produce a counterexample? -- der Mouse USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse philabs!micomvax!musocs!mcgill-vision!mouse Europe: mcvax!decvax!utcsri!mcgill-vision!mouse mcvax!seismo!cmcl2!philabs!micomvax!musocs!mcgill-vision!mouse ARPAnet: utcsri!mcgill-vision!mouse@uw-beaver.arpa "Come with me a few minutes, mortal, and we shall talk."