[fpc-devel] Bug 4004
Gerhard Scholz
gs at g--s.de
Wed Jun 8 13:04:38 CEST 2005
There are two philosophies behind that.
One philosophy is that <type> <op> <type> produces a <type> again (for <op>
out of [ + - * / div and or mod]) ("/" for reals only; "div" and "mod" of
ints only of course). "Widening" is done when the 2 types are not identical
but compatible, e.g. "byte + integer" would be done as "integer(byte) +
integer".
The other philosophy is to wide every operand to a reasonable size (for
example Longint) and do the computation then.
Both philosophies can be found in different compilers. For keeping your code
transportable you should anyhow obey the first philosophy. If neccessary, as
in your code, do the typecast yourself, as I showed you:
i := INTEGER ( Ord(a) ) - Ord(b)
Then you are on the safe side of life.
Your "constant" line, which compiled "correct":
i := Ord('0')-Ord('1')
seems to be a little compiler "weakness".
Gerhard
----- Original Message -----
From: "Colin Western" <mftq75 at dsl.pipex.com>
To: "FPC developers' list" <fpc-devel at lists.freepascal.org>
Sent: Monday, June 06, 2005 10:24 PM
Subject: Re: [fpc-devel] Bug 4004
> Gerhard Scholz wrote:
> <snip>
>
> >It seems that the compiler now sees a "ord(c)" to be a BYTE, and BYTE -
BYTE
> >shall give a BYTE, and -1 is not in the range allowed for a BYTE.
> >
> >
> Thanks for taking a look at this. I am reasonably sure that this
> beheviour is wrong, (otherwise you could never take the difference
> between unsigned values) but I was concerned that as it was flagged
> unreproducable on the bug tracker I had messed up my compilation of fpc
> in some way. As it seems I havn't, perhaps I should re-submit it.
>
> >The line " i := Ord('0')-Ord('1') " in the main program is not
interesting,
> >since it contains a constant expression and is converted to " i := -1 "
by
> >the compiler.
> >
> >
> ... though this should have given a compile time range check error
> because the types are the same
>
> Colin
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
More information about the fpc-devel
mailing list