🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #1941

Re: Lattice 5.04 problem with free()

#1941
From: Gerry Lachac
Date: Wed, 01 Nov 1989 15:26
35 lines
1595 bytes
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
Technical Details
Message-ID: <980@dialogic.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!samsung!uunet!dialogic!gerry
References: <36769@srcsip.UUCP> <37167@lll-winken.LLNL.GOV> <36899@srcsip.UUCP> <112@inesc.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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