cbfalconer@att.net wrote:
Ernst-Ludwig Bohnen <bohnen@mail.desy.de> wrote:
... snip ...
Simplifying your program I observe the same problem:
PROGRAM testsubrange; var i: ShortInt; {signed 16 bit integer} j: SizeType; {unsigned 32 bit word} point : record x,y: real end; {takes 16 bytes} begin i:= 3658; j:= 16; writeln ('result1 = ', i*j); {58528, OK} writeln ('result2 = ', i*SizeOf(point)); {-7008, wrong} end.
My suspicion is that for calculating the second expression the compiler uses wrong operand size (16? bit) instead of 32 (function SizeOf returns a value of SizeType). BTW: -7008+2^16 = 58528
I believe you are simply caught in the silly C value preserving promotion. C does not preserve unsignedness during integer promotion. This is built into the C standard, and means you will be getting signed values in unexpected places.
Kind of. In GPC, the (mathematically) wrong behaviour is not built into the standard, but rather it's an error if the result is out of range. OTOH, an implementation can leave errors undetected, and that's what GPC currently does (i.e., no overflow checking yet). The problem here was that GPC worked with the wrong range (ShortInt rather than Integer). In ISO it's easy, there's only one range, Integer. But GPC also knows larger ranges (LongInt), so it has to choose a range. Of course, this reason shouldn't have made it choose a smaller range, and that's what I fixed now. Frank -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8