Newsgroups: comp.lang.pascal
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!pshuang
From: pshuang@athena.mit.edu (Ping-Shun Huang)
Subject: Re: Third TPascal
In-Reply-To: prknoerr@immd4.informatik.uni-erlangen.de's message of Thu, 27 Jun 1991 13:10:18 GMT
Message-ID: <PSHUANG.91Jun30224335@w20-575-109.mit.edu>
Sender: news@athena.mit.edu (News system)
Organization: Massachusetts Institute of Technology
References: <1991Jun27.131018.26430@informatik.uni-erlangen.de>
Date: Mon, 1 Jul 91 02:43:44 GMT
Lines: 64

To Stuart:

 > (* the var declaration must be here - not after the procedure *)
 > (* that *immediately* will give compile time errors *)

One of the reasons that he specified Turbo Pascal is that this compiler
is more lax than ones which are strictly compatible -- it permits you to
intermix VAR, CONST, FUNCTION, and PROCEDURE declarations in any order
before your main BEGIN-END pair.

A word is a 16-bit integer, by the way.

 > 				       (* ^^^^^^ since "change" is
 > 				       always -1, it would be
 > 				       'tidier' to declare it as a
 > 				       constant up above and not
 > 				       worry about passing it *)

Peter said that change would often be negative at first, *NOT* that it
would always be -1.

 > (* I don't know what TYPE "word" is (pc exclusive?), but this last
 > line will not work unless "value" (VAR'd "given") is ultimately
 > either an INTEGER value or CHAR value, because "temp" is declared as
 > type INTEGER.  You can declare a data type word = INTEGER; up above
 > your global VAR's, and then it would work. *)

The type word is assign-compatible with integer -- when going word to
integer, the value is sign-extended, when going from integer to word the
extra bits are truncated.

-------------------------------------------------------------------------

To Peter:

Except for the below-noted typo, I can't see why this is causing the
range error -- I'm a Pascalholic but the academic/real world has been
forcing me to use Scheme and C instead, respectively, so my recall isn't
as good as it used to be. {sigh} A couple of vague thoughts which are
running through my head involve whether the TP compiler is using
unsigned or signed intermediate results and the fact that an integer -1
is all binary one's in two's complement notation and therefore looks
like MaxWord when casted to word.

Oh, if you want to post puzzles which are clearer, be sure to be more
specific about what happens.  "The first assignment", where the range
error occurs, is unclear; do you mean the first assignment which occurs
in the source code file, or the first one which the computer executes?
That sort of thing needs to be more clearly stated.

If I read your posts correctly, this is being posed as a puzzle and not
as a real problem you're facing which needs solution.  Just in case it
is the latter, though, you should be able to re-write as "IF
(Value+Change)<0 THEN", i.e. process the negative sum as a special case
altogether, rather than doing the sum and then correcting afterwards.

 > var
 >   given : word

{typo? missing a semicolon here after "word"}

--
Above text where applicable is (c) Copyleft 1991, all rights deserved by:
UNIX:/etc/ping instantiated (Ping Huang) [INTERNET: pshuang@athena.mit.edu]
