home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!elroy.jpl.nasa.gov!decwrl!decwrl!apple!mumbo.apple.com!gallant.apple.com!minow.apple.com!user
- From: minow@apple.com (Martin Minow)
- Subject: Re: problem with arithmetic and longints in THINK Pascal
- Sender: news@gallant.apple.com
- Message-ID: <minow-051192112402@minow.apple.com>
- Date: Thu, 5 Nov 1992 19:26:23 GMT
- Distribution: usa
- References: <1992Nov4.212432.3443@mcs.drexel.edu>
- Organization: Macintosh Developer Services
- Followup-To: comp.sys.mac.programmer
- Lines: 20
-
- In article <1992Nov4.212432.3443@mcs.drexel.edu>, udmorrow@mcs.drexel.edu
- (Daniel Morrow) notes that
-
- > x[i] := 10000 + (i - 1) * 10000;
-
- evaluates the expression in short (16-bit) integer arithmetic even though
- the value is being stored in an array of Longints.
-
- While I don't know the Pascal standard well enough to comment, this is
- correct behavior for Ansi C (assuming that variable i is a short int).
- It would seem that the safe way to do this would be, say,
-
- x[i] = (i - 1);
- x[i] = (x[i] * 10000) + 10000;
-
- Substituting a Longint temp variable for x[i] as needed if you want to
- be picky and don't trust the compiler's optimizer to do it for you.
-
- Martin Minow
- minow@apple.com
-