swap(x,y)
RAMontante
bobmon at iuvax.cs.indiana.edu
Fri Sep 8 00:41:09 AEST 1989
jeffrey at algor2.UUCP (Jeffrey Kegler):
-
-B) #define swap(x,y) {int tmp; tmp = x; y = tmp; x = y; }
-
-Consider
-
- if (...) swap(x,y);
- else { do stuff ...; swap(a,b); }
-
-which the Solution A allows, but which won't work with the Solution B,
-unless the first semi-colon is omitted. The second last semi-colon in
-the above example is misleading, but overwise harmless.
gcc accepts the following:
#define swap(a,b) ({int t; t=(a); (a)=(b); (b)=t;})
and the trailing semicolon should be okay here as it follows a
parenthesized expresssion.
More information about the Comp.lang.c
mailing list