[fpc-pascal] Endian issues when porting FPC programs from x86 to other platforms

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Tue Nov 2 11:24:00 CET 2010

Thomas Schatzl wrote:
> Hi,
>> Or maybe this is a moot question if FPC is only so far running on
>> platforms that have the same endian as x86 CPU:s? I have no
>> information on this though...
>> I can see at least these targets:
>> - Windows and Linux on x86 CPU:s
>> - Embedded Linux on ARM CPU:s
> Sparc, PowerPC are big endian, there is an ARM big endian target too.
> Use BEtoN, NtoBE if the source is known to be big endian.
> (http://www.freepascal.org/docs-html/rtl/system/beton.html)
> (http://www.freepascal.org/docs-html/rtl/system/ntobe.html)

All good clean fun. See ENDIAN_LITTLE and ENDIAN_BIG in the FPC 
Programmers' Manual, and also watch out for alignment issues.

I'd point out that if the embedded system is based on a Motorola chip 
and that if this defines that the format transferred across the link is 
big-endian, that this is basically the same as internet "network order" 
and a convenient hack is to use the endian-conversion functions 
associated with socket programming, i.e. HtoNL() etc.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

More information about the fpc-pascal mailing list