Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!apple!bbn!bbn.com!keesan From: keesan@bbn.com (Morris M. Keesan) Newsgroups: comp.lang.c Subject: Re: Type-independent ABS Keywords: abs labs Message-ID: <46916@bbn.COM> Date: 13 Oct 89 20:59:48 GMT References: <1392@cipc1.Dayton.NCR.COM> Sender: news@bbn.COM Reply-To: keesan@bbn.com (Morris M. Keesan) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 16 In article <1392@cipc1.Dayton.NCR.COM> gmaranca@cipc1.Dayton.NCR.COM (Gabriel Maranca) writes: >#define ABS(x) (((x) < 0) ? (-(x)) : (x)) . . . >bill davidsen (davidsen@crdos1.crd.GE.COM) writes: >> 1. instead of -(x) use (-(x)). >Good point. I had overlooked this potential trap in my original macro. I don't see why the extra parentheses are necessary, or their absence a trap. #define ABS(x) ((x) < 0 ? -(x) : (x)) should work fine, because both < and - have higher precedence than ?:, and the whole expansion is protected by the outermost parentheses. It's not as if -(x) were the full expansion of the macro. ------------------------------------------------------------------------------ Morris M. Keesan | Internet: keesan@bbn.com | UUCP: Figure it out from the path |