[fpc-pascal] Binary compatibility between Intel CPU and PowerPC CPU

Adriaan van Os fpc at microbizz.nl
Tue Sep 16 18:26:15 CEST 2008

Roland Turcan wrote:
> Hello FPC-Pascal users discussions!
> What is the best way to keep the binary compatibility among different
> CPU architectures.
> I need to make our own database engine compatible and other binary
> files, that user still can use our data from i386 or PowerPC computer.
> I really don't like the idea to change the order of all numeric
> variables on PowerPC, because it costs time of CPU.
> There must be easier way how to keep the compatibility.
> Could you give me some hints for better solution.

Whether you "like the idea" or not, the best way is as follows:

- add a byte to the header of source data that indicates the endianness, high-endian for PowerPC, 
low-endian for i386
- perform byte swapping if the endianness of source data is different from the endianness of the 
current CPU

With "source data" I mean
- reading files
- reading data over a network

This is best built-into a streaming toolbox, so that it happens automatically.

Adriaan van Os

More information about the fpc-pascal mailing list