Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!samsung!uunet!dialogic!gerry From: gerry@dialogic.UUCP (Gerry Lachac) Newsgroups: comp.sys.amiga.tech Subject: Re: Lattice 5.04 problem with free() Message-ID: <980@dialogic.UUCP> Date: 1 Nov 89 15:26:15 GMT References: <36769@srcsip.UUCP> <37167@lll-winken.LLNL.GOV> <36899@srcsip.UUCP> <112@inesc.UUCP> Reply-To: gerry@dialogic.UUCP (Gerry Lachac) Organization: Dialogic Corp., Parsippany, NJ Lines: 35 In article <112@inesc.UUCP> jmc@inesc.UUCP (Miguel Casteleiro) writes: >In article <36899@srcsip.UUCP>, carpent@SRC.Honeywell.COM (Todd Carpenter) writes: >> >> #define SQR(x) (x*x) > >This macro won't work if you have SQR(a+b), because the result will be >a+b*a+b which is diferent from what you want: (a+b)*(a+b). > >So, try: > >#define SQR(x) ((x)*(x)) Actually, this is a classic case of macro side-effect. This also will produce incorrect results. Take for example the following line of C code: z = SQR(a++); Now, this will actually become: z = ((a++)*(a++)); Which will not produce correct results in certain situations. If a=7 for example, then: a = 7; z = ((7)*(8)); /* variable 'a' now has the value of 9 */ The bottom line is to be aware of side-effects when using macros. -- uunet!dialogic!gerry | "Even a dead plant turns | Dialogic Corporation OR | over a new leaf | 129 Littleton Rd gerry@dialogic.UUCP | when the wind blows." | Parsippany, NJ 07054 | | (201)334-8450