home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6844 < prev    next >
Encoding:
Text File  |  1992-11-23  |  2.1 KB  |  60 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!cs.utexas.edu!torn!blaze.trentu.ca!trentu.ca!tsullivan
  3. From: tsullivan@trentu.ca (The OTHER One True God)
  4. Subject: Re: I found a compiler bug in TP6.0, maybe...
  5. Message-ID: <23NOV199213495226@trentu.ca>
  6. News-Software: VAX/VMS VNEWS 1.41    
  7. Sender: news@trentu.ca (USENET News System)
  8. Organization: Trent University Computer Services Department
  9. References: <1992Nov22.192602.16440@crash>
  10. Date: Mon, 23 Nov 1992 18:49:00 GMT
  11. Lines: 47
  12.  
  13. In article <1992Nov22.192602.16440@crash>, tech@crash.cts.com (Don Bontemps) writes...
  14. >When I attempt to compile the following code, I get a runtime error 202.
  15. >It appears that I am getting an array range check error but the array index
  16. >is within range.  Here an example code listing:
  17. >program range_bug;
  18. >const
  19. >  days : array [-1..6] of string[10] = (' ','Sunday','Monday','Tuesday',
  20. >     {note: integer^}                   'Wednesday','Thursday','Friday',
  21. >                                        'Saturday');
  22. >  num : word = 0;
  23. >         {^--- a WORD is 0-65535. an INTEGER is -32768-32767}
  24. >begin
  25. >  writeln(days[num-1]);
  26. >end.
  27.  
  28.   Your problem comes with the fact that INTEGER and WORD types are 
  29. incompatible. A word is an UNSIGNED number, any number from 0 to 65535 (an 
  30. 8-bit number). An INTEGER is a 7-bit number (0-32767) plus a sign bit, -ve 
  31. or +ve. You are trying to assign a negative value to a type that only 
  32. accepts positive values.
  33.  
  34. >If I turn off the compiler range checking (ie: {$R-}) the program
  35.  
  36.   This is because the compiler no longer cares it it's a word or an 
  37. integer, and will treat it as either at this point (in a c-like way).
  38.  
  39. >executes just fine.  The example code is a small portion of a large application
  40. >that I am currently writing.  If I declare num as an integer, this fixes the
  41. >error but I need num to be declared as a word.  So what gives?  Is this a
  42.  
  43.    Solution: Declare num as a longint. That will solve both the problems.
  44.  
  45.    Tim Sullivan
  46.    tsullivan@trentu.ca
  47.    cstes@blaze.trentu.ca
  48.  
  49. A Disclaimer? Yeah, and people BELIEVE what I write, too...
  50. ---
  51.  "Virtual Reality has NOTHING on Calvin."
  52.        - Suzy, from Calvin and Hobbes
  53.  
  54.