SWAP macro

Mike Beckerman mikeb at copper.UUCP
Tue Jul 8 06:34:00 AEST 1986


I'm a little behind on my news for net.lang.c, but of the articles about the
"SWAP" macro which I've read several have some form of copy involved.  By copy
I mean the use of "memcopy", or a cast to character and copy, etc.  These may
work in many cases, but they could be quite harmful when used on objects
which have the "volatile" storage class.

For example, if the objects were ints, and the swap is implemented as swapping
4 characters for each int, then each of the two ints would be accessed in
some part 8 times (4 to read old 4 bytes, 4 to write new 4 bytes).

Any comments?


	Mike



More information about the Comp.lang.c mailing list