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.
-- Chuck F (cbfalconer@yahoo.com)(cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. http://cbfalconer.home.att.net USE worldnet address!