Joe Smith said:
I agologize in advance for confusion with my newsreaders, the other one of
which is behaving badly despite having been killed and re-installed.
Anyways, am I right to think that if I have this macro, then I'm going to
want to have a 'tmp', 'm' and 'n' of the same type, and that this type could
be different depending on what is in scope during the SWAP?
Right. This:
SWAP(foo, bar)
is *exactly* equivalent to this:
(tmp = foo, foo = bar, bar= tmp)
so exactly the same considerations apply.
Incidentally, it's generally safer to fully parenthesize each macro
argument in a macro definition:
#define SWAP(m, n) (tmp = (m), (m) = (n), (n) = tmp)
It shouldn't matter for any reasonable invocation of SWAP(), but it's
easier to *always* use parentheses than to try to figure out when
they're not required (and force anyone reading and/or maintaining the
code to stop and think about it).
But this amnesia comes after the #IFDEF's, probably right at the end of step
4?
Yes, assuming that "step 4" means "translation phase 4".
Here's my usual example of preprocessor abuse:
#include <stdio.h>
#define SIX 1+5
#define NINE 8+1
int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}