swap() macro
Ben Cranston
zben at umd5.UUCP
Wed Jun 25 04:11:13 AEST 1986
Paul Schauble <Schauble at mit-multics.arpa> asks:
> Can someone construct a version that makes
> int *a, *b;
> swap (*a++,*b++);
>> work right?
Steve Villee <ihnp4!mot!anasazi!steve> replies:
> #define swap(x, y) \
> if (1) \
> { \
> register int *xp, *yp, t; \
> xp = &(x); \
> yp = &(y); \
> t = *xp; \
> *xp = *yp; \
> *yp = t; \
> } \
> else
and goes on to site some special cases in which the "if" implementation
is a big win. Other examples have also been given.
Since the original question was about swapping (int *)s, why do not the
given examples involve (int **)s, i.e. pointers to pointers to ints?
Nailing jelly to a tree again...
--
umd5.UUCP <= {seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben
Ben Cranston zben @ umd2.UMD.EDU Kingdom of Merryland Sperrows 1100/92
umd2.BITNET "via HASP with RSCS"
More information about the Comp.lang.c
mailing list