[fpc-pascal] Data alignment of records

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Dec 9 22:43:49 CET 2010


On 09 Dec 2010, at 22:33, Luis Fernando Del Aguila Mejía wrote:

> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20101209/a9c449e2/attachment.html>


More information about the fpc-pascal mailing list