macros and semicolons
Chris Dollin
kers at hplb.hpl.hp.com
Thu Jun 27 19:45:15 AEST 1991
Mark Hall writes:
NO macro will work for a swap. You suffer from the call-by-name rule
which undid ALGOL in this case. Consider the expansion of SWAP(i,a[i]):
int c; c = i; i = a[i]; a[i] = c;
Disclaimer: I am *not* advocating SWAP macros. But:
#define SWAP(x, y) \
{ int *splodge_x = &(x); int *splodge_y = &(y);
int splodge_t = *splodge_x; \
*splodge_x = *splodge_y; *splodge_y = splodge_t; }
does not suffer from the call-by-name problem (Algol 60 did not have
call-by-reference, but Algol 68 does (in a manner of speaking). Hence Mark's
criticism fails.
However, the amount of effort required to write even a specialised swap macro
should have suggested by now [anyone who hasn't, go read the FAQ] that swap
macros are dead ducks.
Dead, you hear me? D - E - D, DEAD.
We now return you to your regular sniping about the NULL pointer.
--
Regards, Chris ``GC's should take less than 0.1 second'' Dollin.
More information about the Comp.lang.c
mailing list