Path: utzoo!attcan!uunet!clyde.concordia.ca!mcgill-vision!quiche!utility From: utility@quiche.cs.mcgill.ca (Ronald BODKIN) Newsgroups: comp.lang.c Subject: Re: macro inefficiency Message-ID: <5110@quiche.cs.mcgill.ca> Date: 1 Oct 90 20:41:00 GMT References: <2514@cirrusl.UUCP> <5062@quiche.cs.mcgill.ca> <1990Oct1.002217.4945@craycos.com> Organization: SOCS - Mcgill University, Montreal, Canada Lines: 13 In article <1990Oct1.002217.4945@craycos.com> pmk@craycos.com (Peter Klausler) writes: [that #define swap (a,b) { typeof (a) tmp; tmp = a; a = b; b = tmp; } fails for if (..) swap(a,b); else ..., while changing the original to > #define swap (a,b) do { typeof (a) tmp; tmp = a; a = b; b = tmp; } \ > while (0) works]. Quite right (also pointed out to me in email), although mine was better than the original, and if one's compiler doesn't optimize away conditionals with fixed values, it produces better code. However, the idea of using do { ... } while (0) to allow a statement that is closed by a semicolon is a good one. Ron