[fpc-devel] Difficulty in specifying record alignment
Florian Klämpfl
florian at freepascal.org
Mon Oct 21 21:53:42 CEST 2019
Am 21.10.19 um 21:42 schrieb J. Gareth Moreton:
> On 21/10/2019 20:00, Florian Klämpfl wrote:
>> What's the problem with
>>
>> {$push}
>> {$codealign RECORDMIN=16}
>> type complex = record
>> re : real;
>> im : real;
>> end;
>> {$pop}
>>
>> ?
>
> Hi Florian,
>
> I tried that, but that puts each individual field on a 16-byte boundary
Then do:
{$push}
{$codealign RECORDMIN=16}
type dummyrec = record
b : byte;
end;
{$pop}
type complex = record
case byte of
1 : (
re : real;
im : real
);
2 : (alignmentdummy : dummyrec);
end;
I thought I mentioned this trick even somewhere :)
> parameters passed into the function may not be aligned (e.g. when
> deferencing a pointer on the heap after calling, say, "New(complex);"),
> hence why the compiler can only go by the 8-byte aggregate alignment.
No. Data is guaranteed to be aligned at it's natural boundary when it is
passed without further information.
More information about the fpc-devel
mailing list