Igor Bukanov wrote:
On 1/25/06, Robert Dewar <[EMAIL PROTECTED]> wrote:

A convenient way to get the endianness is to use
the System.Bit_Order attribute in Ada.


But this requires to run the program on the target which is not
possible with a cross-compiler. Or is there a trick to declare
something in Ada that would force the program to miscompile depending
on the target endianness?

Regards, Igor

System'Bit_Order is a static constant so you can
do

   Verify_LE : constant :=
               1 / Boolean'Pos (System.Default_Bit_Order =                      
                                Low_Order_First);

which will give a compile time error (division by zero in
a static expression, if you are big endian)

Yes, I think the word "trick" is appropriate here.

In GNAT, you can use something nicer

  pragma Compile_Time_Warning
           (System.Default_Bit_Order = High_Order_First,
            "wrong endianness, program requires little endian target");

and then can if you set the switch to treat warnings as errors.


Reply via email to