Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-05

Record size

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Carsten Bager

I have a data record ("sVar_typ") compiled with the 2.2.5 arm compiler. It has the size of 32728 byte.
Now I try to compile with the 2.4.5 arm compiler it has the size of 32736 byte.

I write the addresses of the variables in the record, they have not changed. It looks like the compiler just adds 8 byte to the record at the end. If I use "Packed" in the record, the 8 byte disappears. Because the record is used in a file, I have to know the size. Is this an indented behavior of the compiler?

Regards Carsten

  sVar_typ = Record
    case Boolean of
      True:(
       version:integer32;
       PanelStart:Integer32;
       ops:spOps_typ;
       aabLuk:aabLukTid_typ;
       text:textS_typ;
       MontPgm:mont_Typ;
       mdI:mPgmDataFeltI_typ;
       Pris:Pris_typ;
       hh:hh_typ;
       pris2tid:pris2tid_typ;
       SommerTid:SommerTid_typ;
       TurFdat:TurFdat_typ;
       TurGdat:TurGdat_typ;
       Modul:Modul_typ;
       MaskinText: array[0..30] of shortString;
       dorGruppe:  array[MinMas..MaxMas] of integer32;
       debug:Debug_typ);
     False:(data:packed array[0..8180] of integer32;
     ckSum:integer32);
  End;
  Writeln(hexstr(longword(@sVar),8));
  Writeln(hexstr(longword(@sVar.version),8));
  Writeln(hexstr(longword(@sVar.PanelStart),8));
  Writeln(hexstr(longword(@sVar.ops),8));
  Writeln(hexstr(longword(@sVar.aabLuk),8));
  Writeln(hexstr(longword(@sVar.text),8));
  Writeln(hexstr(longword(@sVar.MontPgm),8));
  Writeln(hexstr(longword(@sVar.mdI),8));
  Writeln(hexstr(longword(@sVar.Pris),8));
  Writeln(hexstr(longword(@sVar.hh),8));
  Writeln(hexstr(longword(@sVar.pris2tid),8));
  Writeln(hexstr(longword(@sVar.SommerTid),8));
  Writeln(hexstr(longword(@sVar.TurFdat),8));
  Writeln(hexstr(longword(@sVar.TurGdat),8));
  Writeln(hexstr(longword(@sVar.Modul),8));
  Writeln(hexstr(longword(@sVar.MaskinText),8));
  Writeln(hexstr(longword(@sVar.dorGruppe),8));
  Writeln(hexstr(longword(@sVar.debug),8));
  Writeln(hexstr(longword(@sVar.ckSum),8));
  Writeln(sizeof(sVar_typ));

Compiler 2.4.5
000F3694
000F3694
000F3698
000F369C
000F382C
000F38D4
000F57D4
000F5814
000F6014
000F6514
000F6524
000F6604
000F66A4
000F66F8
000F6978
000F69D4
000F88D4
000F8954
000FB668
32736

Compiler 2.2.5
000F3694
000F3694
000F3698
000F369C
000F382C
000F38D4
000F57D4
000F5814
000F6014
000F6514
000F6524
000F6604
000F66A4
000F66F8
000F6978
000F69B8
000F88B8
000F8938
000FB668
32728

Jonas Maebe
to Carsten Bager
Carsten Bager wrote 12 lines
I have a data record ("sVar_typ") compiled with the 2.2.5 arm compiler. It has the size of 32728 byte. Now I try to compile with the 2.4.5 arm compiler it has the size of 32736 byte. I write the addresses of the variables in the record, they have not changed. It looks like the compiler just adds 8 byte to the record at the end. If I use "Packed" in the record, the 8 byte disappears. Because the record is used in a file, I have to know the size. Is this an indented behavior of the compiler?

The size of non-packed records can change at any time between compiler releases. If you need a known layout, you must use a packed record.

Padding at the end of a record is generally added to make sure that if such a record appears in an array, subsequent items all have the required alignment. I don't immediately see why the compiler would think that record needs alignment to a multiple of 16 bytes though (afaik, we don't support any datatypes on the ARM that require such an alignment).

Jonas

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote 6 lines
Padding at the end of a record is generally added to make sure that if such a record appears in an array, subsequent items all have the required alignment. I don't immediately see why the compiler would think that record needs alignment to a multiple of 16 bytes though (afaik, we don't support any datatypes on the ARM that require such an alignment).

See also http://wiki.freepascal.org/User_Changes_2.4.0#Alignment_of_record_variables

And make sure to also read the User Changes pages for 2.4.2 and 2.4.4.

Jonas