comp.lang.ada
 help / color / mirror / Atom feed
* bit numbers in packed arrays of Boolean
@ 2010-08-31 11:14 Stephen Leake
  2010-08-31 11:34 ` Yannick Duchêne (Hibou57)
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stephen Leake @ 2010-08-31 11:14 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-09-02 20:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-31 11:14 bit numbers in packed arrays of Boolean Stephen Leake
2010-08-31 11:34 ` 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

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