From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b657b1c99e7e7039,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: bit numbers in packed arrays of Boolean Date: Tue, 31 Aug 2010 07:14:48 -0400 Message-ID: <82r5hfghjr.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (windows-nt) Cancel-Lock: sha1:ZzcS96M5hCfEclFwmKu3AeIi8so= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 7bc634c7ce429e029e66105431 Xref: g2news1.google.com comp.lang.ada:13869 Date: 2010-08-31T07:14:48-04:00 List-Id: 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