comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: bit numbers in packed arrays of Boolean
Date: Tue, 31 Aug 2010 07:14:48 -0400
Date: 2010-08-31T07:14:48-04:00	[thread overview]
Message-ID: <82r5hfghjr.fsf@stephe-leake.org> (raw)

I was pleasantly surprised to discover that given this code compiled
with GNAT 6.2.1 for an Intel processor:

   subtype Bit_Index_16_Type is Integer range 0 .. 15;
   type Bit_Array_16_Type is array (Bit_Index_16_Type) of Boolean;
   pragma Pack (Bit_Array_16_Type);
   for Bit_Array_16_Type'Size use 16;

   function To_Bit_Array is new Ada.Unchecked_Conversion
     (Source => Interfaces.Unsigned_16,
      Target => Bit_Array_16_Type);

   Word : constant Interfaces.Unsigned_16 := 2#1000_0000_0000_0000#; 
   Bits : constant Bit_Array_16_Type := To_Bit_Array (Word);

the index of Bit_Array_Type indexes the bits of Unsigned_16 in
little-endian order. That is, Bits (15) = 1 (most significant bit), Bits
(0) = 0 (least significant bit).

LRM 13.9(5) says Bit_Array_16_Type and Unsigned_16 have the same
representation, but it does not specifically address the index order.

Is this bit order required by some other clause? Do other compilers
follow it?

I don't have access to GNAT for a big-endian processor; can anyone
confirm what happens there?

Ideally, there would be a way to force the other bit order, as
'Bit_Order does for records.
  
-- 
-- Stephe



             reply	other threads:[~2010-08-31 11:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-31 11:14 Stephen Leake [this message]
2010-08-31 11:34 ` bit numbers in packed arrays of Boolean Yannick Duchêne (Hibou57)
2010-08-31 12:34 ` Niklas Holsti
2010-08-31 12:41   ` Yannick Duchêne (Hibou57)
2010-08-31 13:08     ` Dmitry A. Kazakov
2010-08-31 13:40       ` Yannick Duchêne (Hibou57)
2010-08-31 13:57         ` sjw
2010-08-31 14:07         ` Dmitry A. Kazakov
2010-08-31 14:30         ` Niklas Holsti
2010-09-02 20:09   ` Randy Brukardt
2010-08-31 18:13 ` Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox