Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!bobmon From: bobmon@iuvax.cs.indiana.edu (RAMontante) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Message-ID: <25622@iuvax.cs.indiana.edu> Date: 7 Sep 89 14:41:09 GMT Reply-To: bobmon@iuvax.cs.indiana.edu (RAMontante) Organization: malkaryotic Lines: 20 jeffrey@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.