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

_-jane-_ at web.de _-jane-_ at web.de
Wed Nov 3 09:46:03 CET 2010


Hello!

In order to address the endian problem I use some auxiliary types to access the entities:

(* Standard types *)
type
  t_32u=longint;  // 32 bit unsigned
  t_bool=boolean;

(* Endian types *)
(*$a1 *)
type
  t_intel_32u=object  // Delphi forbids "packed object"; trusting $a1 instead...
    value: t_32u;

    procedure assign(q:t_32u);
    procedure do_add(q:t_32u);
    procedure do_sub(q:t_32u);
    procedure do_or(q:t_32u);
    procedure do_and(q:t_32u);
    procedure do_xor(q:t_32u);
    procedure do_and_not(q:t_32u);
    procedure do_not;
    function is_equal(const q:t_intel_32u):t_bool;
    end;

  t_motorola_32u=object
  private
    x: packed array [0..4-1] of t_8u;  // or t_32u
  public
    function value:t_32u;
    procedure assign(q:t_32u);
    procedure do_add(q:t_32u);
    procedure do_sub(q:t_32u);
    procedure do_or(q:t_32u);
    procedure do_and(q:t_32u);
    procedure do_xor(q:t_32u);
    procedure do_and_not(q:t_32u);
    procedure do_not;
    function is_equal(const q:t_motorola_32u):t_bool;
    end;

The corresponding code has some ifdefs. I then use these types to build my exchange types such as:

type
  t_my_record=packed record
   a,b: t_motorola_32u;
   c: packed array [0..8-1] of t_motorola_32u;
   end;

The interface for all these types is more or less the same.
In the application I always read the values via "value" and write them via "assign".
All exchange types should be packed records with only such types.
BTW: I often use t_motorola_24u to access ASPI stuff...

Jasper
PS: Wouldn't it make sense to have such types in a standard library for FPC?
___________________________________________________________
WEB.DE DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit 
gratis Notebook-Flat! http://produkte.web.de/go/DSL_Doppel_Flatrate/2



More information about the fpc-pascal mailing list