macros and semicolons

Michael R. Miller mrm at nss1.com
Fri Jun 28 23:45:17 AEST 1991


In article <160662 at pyramid.pyramid.com>, markhall at pyrps5.pyramid.com (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;

How about:

#define swap(x, y)  (x ^= y ^= x ^= y)

Why won't this do the swap as requested?  I've done this before.  The
only presumption, which was carried forward from the above text, is
the types are compatible (not only size but type).



More information about the Comp.lang.c mailing list