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

Marco van de Voort marcov at stack.nl
Tue Nov 2 09:27:33 CET 2010

In our previous episode, Bo Berglund said:
> Now, however, the problem may be complicated because the program may
> well run on a CPU that is using the *same* endian structure as the
> original instrument in which case of course the swaps should not be
> done.


> So I need some detector or other to decide if swaps are needed.
> Is there some commonly used function to handle this or is there some
> conditional directive one can use to control the compiler to "do the
> right thing" depending on the target CPU endian?

See e.g. the CHM package. It has the same problem, the file structure is
little endian (since windows), but the package may run on e.g. PowerPC.

The routine in the url below is used for that. (in this case ntole, but
ntobe if your storage is bigendian)


These routines are afaik inline and a no-op if the endianness is the same.

More information about the fpc-pascal mailing list