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

Autoconf already has tests for things like this. Something along the lines of:

const char D_P_S_4[sizeof(void *) == 4 : -1 : 1];
const char D_P_S_8[sizeof(void *) == 8 : -1 : 1];

Then see which compiles, or grep the error messages.


Right, but are there any way to learn about endianess of the paltform
or the direction of stack growth just from knowing that program
compiles or not? GCC nows about this and it would be nice if there is
a way to expose these.

A convenient way to get the endianness is to use
the System.Bit_Order attribute in Ada. Here is
a little function you can use in your program,
easily called from C

   function is_little_endian return int;
   pragma Export (C, is_little_endian);
   -- returns 1 if LE, 0 if BE

   with System; use System;
   function is_little_endian return int is
   begin
      return Boolean'Pos (Default_Bit_Order = Low_Order_First);
   end;

or, if you don't mind being GNAT specific

   function is_little_endian return int is
   begin
      return Standard'Default_Bit_Order;
   end;

It would be nice to have this query more directly
available in C (perhaps there is a way, but I don't
know it, of course you can rig up some trick code
that tests it).


Regards, Igor


Reply via email to