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,4158e4de0999807a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o13g2000cwo.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: GNAT 4.0 strange behaviour Date: 11 Sep 2005 17:36:52 -0700 Organization: http://groups.google.com Message-ID: <1126485412.479800.227880@o13g2000cwo.googlegroups.com> References: <4324c57b$0$17248$8fcfb975@news.wanadoo.fr> NNTP-Posting-Host: 69.170.70.49 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1126485417 1807 127.0.0.1 (12 Sep 2005 00:36:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 12 Sep 2005 00:36:57 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: o13g2000cwo.googlegroups.com; posting-host=69.170.70.49; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.lang.ada:4582 Date: 2005-09-11T17:36:52-07:00 List-Id: James wrote: > This is a very small program compiled under linux debian with gnat 4 > based on gcc 4.0 > The output of the program is > 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > which is of course not right... > If line labelled 1 is removed and replaced by line labelled 2, the > output is correct. > The output is also correct if part 1 is replaced by part 2. > Any advice or place where I could send a bug report? > > with Text_Io; > use Text_Io; > with Interfaces; > use Interfaces; > > > procedure Toto is > type Intboard is new Unsigned_64; > for Intboard'Size use 64; > type Bit is new Integer range 0..1; > for Bit'Size use 1; You seem to think that Bit is an unsigned type. It is not. It is a derived type from Integer, which is a signed type. If you want an unsigned integer with a range of 0..1 you should declare: type Bit is mod 2; Ada unsigned integer types are defined using modular types. I am willing to bet the answer will improve if you use a modular type. Strictly speaking, the subtypes used in part 1 below do not match the subype used in Bitboard array index definition. The part 1 approach to indexing look suspiciuosly like C coding logic. The part 2 approach is closer to a classical Ada. The most correct and maintainable approach to the looping is: for I in A_B'Range loop A_B(I) := 1; Put(Bit'Image(A-B(I))); end loop; Clearly your goal is to set each element of A_B to 1 and then print a string representation of that element. The approack shown above will correctly satisfy that goal even if the index range of A_B should change sometime in the future due to changes in system requirements. > type Bitboard is array (0..63) of Bit; > pragma Pack(Bitboard); > for Bitboard'Size use 64; > > A_B : Bitboard; > A_I : Intboard; > for A_I'Address use A_B'Address; --label1 > -- for A_B'Address use A_I'Address; --label2 > > begin > --part 1 > for I in 0 .. 7 loop > for J in 0 .. 7 loop > A_B(I*8+J) := 1; > Put(Bit'Image(A_B(I*8+J))); > end loop; > end loop; > > --part 2 > -- for I in 0 .. 63 loop > -- A_B(I) := 1; > -- Put(Bit'Image(A_B(I))); > -- end loop; > end Toto; Jim Rogers