Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!umriscc!mcs213f.cs.umr.edu!mcastle From: mcastle@mcs213f.cs.umr.edu (Mike Castle (Nexus)) Newsgroups: comp.lang.pascal Subject: Re: Help Me!!! What's wrong with this simple problem? Message-ID: <1759@umriscc.isc.umr.edu> Date: 28 Nov 90 04:48:47 GMT References: <527@shum.UUCP> <19956@oolong.la.locus.com> <28893@shamash.cdc.com> Sender: news@umriscc.isc.umr.edu Organization: University of Missouri - Rolla Lines: 42 In article <28893@shamash.cdc.com> mpe@shamash.UUCP (Mike Ebsen) writes: >What's wrong with this problem in Turbo Pascal 5.0... > > Program test; > var > i : integer; > j : word; > begin > j:=3; > i:=j-10; > writeln(j,' ',i); > end. > >My compiler tells me that the assignment of -7 into i (an integer) >is an error. Well, it first tries to evaluate j-10. Since j is a word, it tries to evaluate j-10 as a word. A word ranges from 0..65535. So -7 is an error. That's the way pascal works, I assume, as opposed to an error. If it put 3 into i first, and THEN subtracted 7, no problem, but it doesn't work that way. You can defeat this by putting in the compiler directive {$R-} or changing it range checking to off from the options menu, but I wouldn't advise it. At least, not until you've gotten all the other bugs worked out and you wanted to save some speed and size. By turning off the range checking, I got it to print out 3 and -7, but that's no guarantee it would work all the time. In short, try this: i := j; i := i-7; Always pays to look up the run time errors in the manual too.... :-> -- Mike Castle (Nexus) S087891@UMRVMA.UMR.EDU (preferred) | ERROR: Invalid mcastle@mcs213k.cs.umr.edu (unix mail-YEACH!)| command 'HELP' Life is like a clock: You can work constantly, and be right | try 'HELP' all the time, or not work at all, and be right twice a day. |