Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!ccwf.cc.utexas.edu From: mjensen@ccwf.cc.utexas.edu (Marc S. Jensen) Newsgroups: comp.lang.pascal Subject: Re: Help Me!!! What's wrong with this simple problem? Message-ID: <40343@ut-emx.uucp> Date: 29 Nov 90 05:19:52 GMT References: <527@shum.UUCP> <19956@oolong.la.locus.com> <28893@shamash.cdc.com> Sender: news@ut-emx.uucp Reply-To: mjensen@ccwf.cc.utexas.edu (Marc S. Jensen) Organization: The University of Texas at Austin Lines: 36 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. The problem is not the -7, but the fact that j is declared as being of type word. In TP, a word is defined as an unsigned 16-bit data type, whereas an integer is a signed 16-bit type. It is therefore possible to store numbers in a word that cannot possibly fit in an integer. (Numbers from 32768 through 65535 can be words but not integers.) To safeguard against this, the compiler disallows assigning a word value to an integer variable. In your example, you could either declare j : integer, or, if you *need* it to be a word, i : longint or i : word. -- Marc Jensen mjensen@ccwf.cc.utexas.edu University of Texas at Austin ----- "Never attribute to malice that which is adequately explained by stupidity!"