🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Defining macros (was Re: Lattice)

#2006
From: Joe Smith
Date: Fri, 03 Nov 1989 23:56
22 lines
1550 bytes
In article <36899@srcsip.UUCP> carpent@SRC.Honeywell.COM (Todd Carpenter) writes:
>As long as we are on the subject of Lattice, why doesn't this macro seem to
>work?  (I'm rather new to macrodom, so this is probably a silly one) I
>have some terribly long nasty expressions that need to be squared, and
>SQR(moocow) never returns what I expect:
>#define SQR(x) (x*x)

That definition is guarenteed to produce the wrong results if the "nasty
expression" includes addition, subtraction, or division.

SQR(2+5) = (2+5*2+5) = (2+10+5) = (17) != 7*7

You need to put parenthises around every dummy argument and around the
whole thing.  

#define SQR(x) ((x)*(x))

-- 
Joe Smith (408)922-6220 | SMTP: JMS@F74.TYMNET.COM or jms@gemini.tymnet.com
McDonnell Douglas FSCO  | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-D21    | PDP-10 support: My car's license plate is "POPJ P,"
San Jose, CA 95161-9019 | narrator.device: "I didn't say that, my Amiga did!"
Technical Details
Message-ID: <744@tardis.Tymnet.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!rutgers!cmcl2!nrl-cmf!think!snorkelwacker!tut.cis.ohio-state.edu!mailrus!bbn!oliveb!tymix!tardis!jms
References: <36769@srcsip.UUCP> <37167@lll-winken.LLNL.GOV> <36899@srcsip.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!rutgers!cmcl2!nrl-cmf!think!snorkelwacker!tut.cis.ohio-state.edu!mailrus!bbn!oliveb!tymix!tardis!jms
From: jms@tardis.Tymnet.COM (Joe Smith)
Newsgroups: comp.sys.amiga.tech
Subject: Defining macros (was Re: Lattice)
Summary: Add parens
Message-ID: <744@tardis.Tymnet.COM>
Date: 3 Nov 89 23:56:37 GMT
References: <36769@srcsip.UUCP> <37167@lll-winken.LLNL.GOV> <36899@srcsip.UUCP>
Reply-To: jms@tardis.Tymnet.COM (Joe Smith)
Organization: McDonnell Douglas Field Service Co, San Jose CA
Lines: 22