David James wrote:
The following program:
program test9(input,output); const maxnum=4; TYPE T1=RECORD a1:array[1..maxnum] of byte; END; T2=RECORD a2:packed array[1..maxnum] of byte; END; T3=RECORD a3:packed array[1..maxnum] of 0..255; END; T4=RECORD a4:array[1..maxnum] of 0..255; END; begin writeln('t1: ',sizeof(t1):1); writeln('t2: ',sizeof(t2):1); writeln('t3: ',sizeof(t3):1); writeln('t4: ',sizeof(t4):1); end.
gives
t1: 4 t2: 4 t3: 16 t4: 16
under GPC20010306, and gives 4,4,4,16 under GPC19991030.
That is the PACKED ARRAY of 0..255 occupied 4 bytes under the old version and now occupies 16 bytes. Whilst I clearlyu have a workaround by switching from 0..255 to byte, that behaviour doesn't seem right to me.
Indeed, this seems like a bug to me (daj14.pas). GPC supports a non-standard `packed' for subranges (shrinking them to the smallest size possible, as opposed to the more efficient natural integer size), so the followwing is also a work-around (and the real bug seems to be that GPC doesn't carry over the `packed' to the array component).
a3:packed array[1..maxnum] of packed 0..255;
Frank