[fpc-devel] data alignment and int64 (or qword, maybe any single piece of size 8 if any)

Пётр Косаревский ppkk at mail.ru
Mon May 15 12:47:57 CEST 2006


It seems, that docs are outdated.

Default data alignment in records is expected to be wordly (i386, win32).

But if a record has int64 (or qword) element, I get unexpected overheads.

It's easily avoidable (with {$PACKRECORDS 1} or {$A1}; even with {$A-} [which is expected to work only on MAC, according to docs]), but unexpected.

type
  a= record
     a: longword;
     b: longword;
     c: longword;
     end; // 12 expected

  b= record
     ab: int64;
     c: longword;
     end; // 12 expected

  c= record
     ab: array[0..7] of byte;
     c: byte; // 1b overhead expected
     d: word;
     e: byte; // 1b overhead expected
     end; // 14 expected

  d= record
     ab: int64;
     c: byte; // 1b overhead expected
     d: word;
     e: byte; // 1b overhead expected
     end; // 14 expected

  e= record
     a: byte;
     b: byte;
     c: word;
     d: longword;
     e: word;
     f: byte;
     g: byte;
     end; // well, 12 expected

begin
writeln(sizeof(a)); // 12 ok!
writeln(sizeof(b)); // 16    ???
writeln(sizeof(c)); // 14 ok!
writeln(sizeof(d)); // 16    ???
writeln(sizeof(e)); // 12 ok!
end. // I don't know the numbers on other platforms/systems



More information about the fpc-devel mailing list