Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!sdd.hp.com!hplabs!pyramid!pyrps5.pyramid.com!markhall From: markhall@pyrps5.pyramid.com (Mark Hall) Newsgroups: comp.lang.c Subject: Re: macros and semicolons Summary: NO macro will work in general Message-ID: <160662@pyramid.pyramid.com> Date: 26 Jun 91 20:23:02 GMT References: <1991Jun24.213932.595@otago.ac.nz> <1991Jun24.144701.8479@world.std.com> Sender: news@pyramid.pyramid.com Organization: Pyramid Technology Corporation, Mountain View Lines: 16 In article <1991Jun24.213932.595@otago.ac.nz> andrew@otago.ac.nz writes: >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} Forgive me for this unsufferable horn-tooting; I just couldn't resist (I also couldn't believe no one else sent this reply :-). . . . 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; -Mark Hall (smart mailer): markhall@pyrps5.pyramid.com (uucp paths): {ames|decwrl|sun|seismo}!pyramid!markhall