[fpc-pascal] FPC Advanced Records

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Mar 9 22:35:48 CET 2012


On 09 Mar 2012, at 22:26, Mark Morgan Lloyd wrote:

> Thanks Jonas, I don't think I need to do it but I thought it was a fair question: better safe than sorry.
> 
> OK, so hopefully I can get away with another. I'm looking at a program written in Delphi, which reads a file containing the image of an IBM mainframe tape. This has a record:
> 
> Type TAWSHeader=Record
>       ThisSize: Word;
> ..

If you want a record to have a predictable layout, always either
a) use {$packrecords c} if it's a translation of a C struct, or
b) declare it as "packed"

In other cases, you can (and will) have problems across different platforms or even compiler versions.

> but is there any way to define something like an endianness-correcting type, i.e.:
> 
> Type TAWSHeader=Record
>       ThisSize: WordLE;
> ..
> 
> where by the time ThisSize is accessed any disparity has been corrected?

No.


Jonas


More information about the fpc-pascal mailing list