Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!decwrl!waikato.ac.nz!comp.vuw.ac.nz!canterbury!otago.ac.nz!andrew From: andrew@otago.ac.nz Newsgroups: comp.std.c Subject: macors and semicolons Message-ID: <1991Jun24.213932.595@otago.ac.nz> Date: 24 Jun 91 10:11:08 GMT Organization: University of Otago, Dunedin, New Zealand Lines: 36 I often get pissed off with the C pre-processor. Here is one thats been getting up my wick for months. #define SWAP(a, b) {int c; c = a; a = b; b = c} if (spam) SWAP(a, b); else a++; These lines of code do a simple substitution if (spam) { int c; c = a; a = b; b = c }; else a++; notice the }; on the last line of the substitution. This means that the else is a syntax error! With swap, there are a number of simple solutions... #define SWAP(a, b) (b = (b ^ a) ^ (a = (b ^ a) ^ a)) simple hu? but it only words with ints or longs. Question time.... how do I define a swap macro that swaps two doubles, allows the ';' on the end of the macro call, but does not cause a systax error when used in this context? Andrew andrew@otago.ac.nz