home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
- From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
- Subject: Re: I found a compiler bug in TP6.0, maybe...
- Message-ID: <dmurdoch.300.722537145@mast.queensu.ca>
- Lines: 36
- Sender: news@knot.ccs.queensu.ca (Netnews control)
- Organization: Queen's University
- References: <1992Nov23.061222.3675@u.washington.edu> <JgLouB1w165w@abyss.wa.com> <1eqvj5INNprl@bigboote.WPI.EDU>
- Date: Mon, 23 Nov 1992 16:45:46 GMT
-
- In article <1eqvj5INNprl@bigboote.WPI.EDU> gregs@wpi.WPI.EDU (Floppy) writes:
-
- >>> > writeln(days[num-1]);
-
- > This really is a bug. The manual clearly states that when an
- >arithmetic expression contains two integral types, both numbers will first be
- >converted to the smallest integral type containing the entire range of both of
- >the original types. In this case, the smallest such type is longint, since
- >the two original types were word and shortint.
-
- No, that's not how the expression is parsed. It's not "(num) + (-1)", it's
- "(num) - (1)". Both "num" and "1" are compatible with the word type, so
- that's how the expression is evaluated.
-
- It's dangerous to rely on the automatic conversions, because it's not always
- obvious how the compiler will apply them. One that may surprise, but which
- is compatible with the language definition, is the following:
-
- var
- b1,b2 : byte;
- begin
- b1 := 255;
- b2 := 255;
- if b1*b2 < 0 then
- writeln('Surprise!');
- end.
-
- BTW, I've just discovered that this is a bug in BP 7.0: it behaves the same
- as TP 6 in this expression, even when overflow checking is enabled. It does
- an unsigned multiply (which doesn't overflow), checks for overflow (and
- doesn't see any), then does a signed comparison with 0 and sees a negative.
-
- Duncan Murdoch
-
- Duncan Murdoch
- dmurdoch@mast.queensu.ca
-