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