[fpc-pascal] Delphi-FPC portable code for endian conversion

Bo Berglund bo.berglund at gmail.com
Fri Jun 3 21:58:41 CEST 2016


I have a class file implementing interfaces for talking to an embedded
system and I intend to use this class for both Delphi (on Windows) and
FPC (on ARM Linux)
One part of this class deals with transfers of binary data to/from the
embedded system, which is based on a Motorola MCU and is BigEndian.
When the class is compiled on Windows it needs to swap 2- and 4-byte
values to correct for endian differences between Intel and Motorola
CPU:s.
I have a working code to do this on Windows, but on FPC I would like
to use the BEToN() and NToBE functions to convert 16 bit words, 32 bit
integers and 32 bit floats (single prec) as needed. 
I.e. if running in Delphi on Windows use the Swap and Swap4 functions
but if running on FPC use the BEToN and NToBE.
I think I have understood that these functions will convert only if
the current system is using a different endian than specified by the
call.

I have tried to figure out a set of {$IFDEF } statements but so far
with no success.


-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list