SizeOf packed record is different when record placed into packed array [0..0], see source please
Hi All. program test; type t1 = packed record item1 : byte; item2: byte; item3: byte; end; t2 = packed array [0..0] of t1; begin writeln ('SizeOf (t1): ', SizeOf (t1)); writeln ('SizeOf (t2): ', SizeOf (t2)); readln; end. Output of program: SizeOf (t1): 3 SizeOf (t2): 4 Could anybody tell me - why? Thanks. software: gpc version 2.1 (20020510), based on 2.95.3 20010315 (release) Linux RedHat 2.5.52
My guess is that the array elements are being aligned on word boundaries. Grant At 9:25 PM +0300 31/1/03, Ingvar Marny wrote:
Hi All.
program test;
type t1 = packed record item1 : byte; item2: byte; item3: byte; end; t2 = packed array [0..0] of t1;
begin writeln ('SizeOf (t1): ', SizeOf (t1)); writeln ('SizeOf (t2): ', SizeOf (t2)); readln; end.
Output of program:
SizeOf (t1): 3 SizeOf (t2): 4
Could anybody tell me - why?
Thanks.
software:
gpc version 2.1 (20020510), based on 2.95.3 20010315 (release) Linux RedHat 2.5.52
-- ------------------------------------------------------------------- Grant Jacobs Ph.D. BioinfoTools ph. +64 3 476 1820 (office, after 10am) PO Box 6129, or +64 25 601 5917 (mobile) Dunedin, gjacobs@bioinfotools.com NEW ZEALAND. Bioinformatics tools: deriving knowledge from biological data Bioinformatics tools - software development - consulting - training Check out the website for more details: http://www.bioinfotools.com The information contained in this mail message is confidential and may be legally privileged. Readers of this message who are not the intended recipient are hereby notified that any use, dissemination, distribution or reproduction of this message is prohibited. If you have received this message in error please notify the sender immed- iately and destroy the original message. This applies also to any attached documents.
Ingvar Marny wrote:
program test;
type t1 = packed record item1 : byte; item2: byte; item3: byte; end; t2 = packed array [0..0] of t1;
begin writeln ('SizeOf (t1): ', SizeOf (t1)); writeln ('SizeOf (t2): ', SizeOf (t2)); readln; end.
Output of program:
SizeOf (t1): 3 SizeOf (t2): 4
Could anybody tell me - why?
Packed arrays are currently accessed in half-word entities (i.e., 16 bits on most systems). This might seem unlogical, but the packing is only done within the array, not outside. I might change it sometime because it also causes other (small) problems, but it's not trivial to do ... 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: 51FF C1F0 1A77 C6C2 4482 4DDC 117A 9773 7F88 1707
participants (3)
-
Frank Heckenbach -
Grant Jacobs -
Ingvar Marny