[fpc-devel] Rules about record types and internal storage

Jonas Maebe jonas at freepascal.org
Thu Apr 2 21:32:06 CEST 2020


On 02/04/2020 21:25, J. Gareth Moreton wrote:
> Am I right in thinking that, for C alignment, each field is aligned
> according to its data size? For example, if you had:
> 
> TType = record
>   Field1: Byte
>   Field2: LongInt;
> end;
> 
> Are there are three unused bytes between Field1 and Field2 and the
> structure as a whole is 8 bytes long and aligned to a 4-byte boundary? 

On most platforms, yes. Probably not on 16 bit platforms.

> I'm trying to find the page that explains all that, and also exceptional
> cases where the data size is not necessary the same as the minimum
> alignment.

"C alignment" is actually a bad name. It's in fact the ABI alignment
(which is indeed what C uses), and hence this is different depending on
architecture and OS. As a result, there is no page that explains it all,
since you have to look it up in the ABI documentation of every
individual platform.

Some examples of non-matching alignments on Darwin/i386:
* double is aligned to 4 bytes
* extended is aligned to 16 bytes


Jonas


More information about the fpc-devel mailing list