home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / mac / programm / 18049 < prev    next >
Encoding:
Text File  |  1992-11-06  |  1.2 KB  |  34 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. 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
  3. From: minow@apple.com (Martin Minow)
  4. Subject: Re: problem with arithmetic and longints in THINK Pascal
  5. Sender: news@gallant.apple.com
  6. Message-ID: <minow-051192112402@minow.apple.com>
  7. Date: Thu, 5 Nov 1992 19:26:23 GMT
  8. Distribution: usa
  9. References: <1992Nov4.212432.3443@mcs.drexel.edu>
  10. Organization: Macintosh Developer Services
  11. Followup-To: comp.sys.mac.programmer
  12. Lines: 20
  13.  
  14. In article <1992Nov4.212432.3443@mcs.drexel.edu>, udmorrow@mcs.drexel.edu
  15. (Daniel Morrow) notes that
  16.  
  17. >         x[i] := 10000 + (i - 1) * 10000;
  18.  
  19. evaluates the expression in short (16-bit) integer arithmetic even though
  20. the value is being stored in an array of Longints.
  21.  
  22. While I don't know the Pascal standard well enough to comment, this is
  23. correct behavior for Ansi C (assuming that variable i is a short int).
  24. It would seem that the safe way to do this would be, say,
  25.  
  26.     x[i] = (i - 1);
  27.     x[i] = (x[i] * 10000) + 10000;
  28.  
  29. Substituting a Longint temp variable for x[i] as needed if you want to
  30. be picky and don't trust the compiler's optimizer to do it for you.
  31.  
  32. Martin Minow
  33. minow@apple.com
  34.