Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!rpi!zaphod.mps.ohio-state.edu!samsung!umich!sharkey!amara!mcdaniel From: mcdaniel@adi.com (Tim McDaniel) Newsgroups: comp.lang.c Subject: Re: A define problem Message-ID: Date: 9 Jan 91 14:19:08 GMT References: <440@bally.Bally.COM> <1991Jan8.012923.3390@oswego.Oswego.EDU> <4613@sactoh0.SAC.CA.US> Sender: news@adi.COM Distribution: usa Organization: Applied Dynamics International, Inc.; Ann Arbor, Michigan, USA Lines: 19 In-reply-to: jak@sactoh0.SAC.CA.US's message of 9 Jan 91 02:09:42 GMT I suspect that the program Siva Chelliah actually compiled had #define half(x) x /2 without the paren- ^ ^ theses. In that case, half(i-5) is 3 when i==5. Rule of thumb: PARENTHESIZE THE RESULT OF A MACRO, AND PARENTHESIZE THE USE OF EACH ARGUMENT. Even #define half(x) (x)/2 fails, if someone uses it in an expression with an operator with higher precedence than /, as in ~half(i) This Silly Little Macro should be written as #define half(x) ((x)/2) -- Tim McDaniel Applied Dynamics Int'l.; Ann Arbor, Michigan, USA Work phone: +1 313 973 1300 Home phone: +1 313 677 4386 Internet: mcdaniel@adi.com UUCP: {uunet,sharkey}!amara!mcdaniel