SWAP macro
mouse at mcgill-vision.UUCP
mouse at mcgill-vision.UUCP
Sat Jul 12 17:10:01 AEST 1986
In article <857 at bu-cs.UUCP>, bzs at 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 at uw-beaver.arpa
"Come with me a few minutes, mortal, and we shall talk."
More information about the Comp.lang.c
mailing list