C Program to create generic macro to swap two values
The best all-around solution is probably to forget about using a
macro,
unless you're willing to pass in the type as a third argument.
(Also,
if you're trying to swap entire structures or arrays,
you probably want to
exchange pointers
instead.)
If you're worried about the use of an ugly temporary, and know
that your machine provides an efficient exchange instruction, convince your
compiler vendor to recognize the standard three-assignment swap
idiom in the optimization phase.
No comments:
Post a Comment