[fpc-pascal] Packed record
Florian Klaempfl
florian at freepascal.org
Thu Oct 20 09:47:12 CEST 2005
Adriaan van Os wrote:
> Florian Klaempfl wrote:
>
>> Carsten Bager wrote:
>>
>>> I am using the compiler on an embedded Arm7 platform (no
>>> operating system). So fare things are working ok, but now I have
>>> discovered a problem when packing records (Vi have to maintain
>>> bindery compatibility with older systems)
>>> If I have a packed record like this
>>>
>>> Test_typ= packed record
>>> B:byte;
>>> I:LongInt;
>>> end;
>>>
>>> Var
>>> Test:Test_typ;
>>>
>>> Begin
>>> Test.i:=1;
>>> Write(test.i);
>>> End.
>>>
>>>
>>> The output is wrong.
>>
>>
>> Usual ARM cores can't handle unaligned memory accesses and on e.g.
>> arm-linux you
>> would get a sigbus exception on your code.
>>
>>> If I remove "Packed" the output is OK.
>>
>>
>> What can do is:
>> - modify your pascal code:
>>
>> l:longint;
>> move(l,Test.i,sizeof(Test.i)); // move can handle unaligned access
>> and that how
>> C code usually solves it
>>
>> - add an exception handler to your OS to catch unaligned access and
>> fix things
>> but emulating the memory access
>
>
> - or fix the compiler to ignore "packed" for ARM. This could be a
> compiler switch, on by default for ARM (gpc has --ignore-packed).
>
No. He needs to maintain binary compatibility with an older system so this is no
option, see initial post.
More information about the fpc-pascal
mailing list