[fpc-pascal] Packed record
    Florian Klaempfl 
    florian at freepascal.org
       
    Thu Oct 20 08:49:54 CEST 2005
    
    
  
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
> 
> Regards 
> 
> Carsten 
> 
> ---------------------------------- 
> Compiler version 
> Free Pascal Compiler version 2.0.0 [2005/05/15] for arm 
> Copyright (c) 1993-2005 by Florian Klaempfl 
> Target OS: Linux for ARM 
> 
    
    
More information about the fpc-pascal
mailing list