Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!amdahl!uunet!mcvax!enea!Urd!newsuser From: newsuser@LTH.Se (Lund Institute of Technology news server) Newsgroups: comp.sys.mac.programmer Subject: Re: MPW Pascal Bug? Or am I wrong. Message-ID: <1988Jun24.174158.9579@LTH.Se> Date: 24 Jun 88 16:41:57 GMT References: <3203@polyslo.UUCP> Reply-To: roland@DNA.LTH.Se (Roland Mansson) Organization: Computer Science, Lund Institute of Technology, Sweden Lines: 30 Summary:No bug In article <3203@polyslo.UUCP> dorourke@polyslo.UUCP (David O'Rourke) writes: >This isn't a serious problem, but I thought I'd share it with netland anyways. >Given the following peice of code: > >procedure doSomething; > var > X, Y : INTEGER; > Z : LONGINT; > begin > Z := X * Y; > end; {doSomething} > >If X*Y causes an overflow and I have overflow checking turned off it stores >the wrong result, usually negative, in Z even though Z is a LONGINT. Now is >this what the compiler is suppose to do, or is it suppose to convert to the >LONGINT. This is not a bug. Check the MPW Pascal manual, page 4-7. "When both operands of an operator are of type integer, 16-bit operations are always performed and the result is of type integer (truncated to 16 bits if necessary)." A simple solution is to change the assignment statement to Z := ord4 (X) * Y -- Roland Mansson, Dept of Comp Sc, Lund University, Box 118, S221 00 Lund, Sweden Phone: +46-46109640 (work), +46-46111539 (home) Bitnet: lthlib@seldc52 Internet: roland@dna.lth.se or roland%dna.lth.se@uunet.uu.net UUCP: {uunet,mcvax}!enea!dna.lth.se!roland AppleLink: IT0073