Sign in Join

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

Mailing lists / fpc-pascal / 2010-12

Data alignment of records

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Luis Fernando Del Aguila Mejía

I can not understand the data alignment of records. I compiled the program PackRecordsDemo,
http://www.freepascal.org/docs-html/ref/refsu16.html#x40-470003.3.2 sample documentation.
But the result on my computer is different:

Size Trec1 : 4 Offset B : 2
Size Trec2 : 3 Offset B : 1
Size Trec3 : 2 Offset B : 1
Size Trec4 : 2 Offset B : 1
Size Trec5 : 5 Offset B : 1 Offset C : 4 //diferent Size Trec6 : 5 Offset B : 1 Offset C : 4 //diferent Size Trec7 : 9 Offset B : 1 Offset C : 8 //diferent Size Trec8 : 9 Offset B : 1 Offset C : 8 //diferent

Can someone explain to me, about the alignment of registration data and other variables.
My computer is : intel Quad CPU Q6600
S.O. Windows Vista

Att.
Luis Del Aguila

Jonas Maebe
to Luis Fernando Del Aguila Mejía
Luis Fernando Del Aguila Mejía wrote 12 lines
I can not understand the data alignment of records. I compiled the program PackRecordsDemo, http://www.freepascal.org/docs-html/ref/refsu16.html#x40-470003.3.2 sample documentation. But the result on my computer is different: Size Trec1 : 4 Offset B : 2 Size Trec2 : 3 Offset B : 1 Size Trec3 : 2 Offset B : 1 Size Trec4 : 2 Offset B : 1 Size Trec5 : 5 Offset B : 1 Offset C : 4 //diferent Size Trec6 : 5 Offset B : 1 Offset C : 4 //diferent Size Trec7 : 9 Offset B : 1 Offset C : 8 //diferent Size Trec8 : 9 Offset B : 1 Offset C : 8 //diferent

The output in the manual is wrong (and it should probably use ptrint rather than longint), and probably from a very old FPC version. The output you posted above is the expected output.

Can someone explain to me, about the alignment of registration data and other variables.

The alignment of an array is the same as the alignment of its element types, so for an array of byte that is 1 -> all of the array fields are aligned to 1 byte. I don't know what you mean by "registration data".

Jonas