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,442eb9212004f30 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!r66g2000hsg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Problem using Ada.Text_IO.Modular_IO Date: Wed, 9 Jul 2008 12:22:50 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4eab7055-df3d-4d56-87da-8248829da1da@26g2000hsk.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1215631370 29696 127.0.0.1 (9 Jul 2008 19:22:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 9 Jul 2008 19:22:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r66g2000hsg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1052 Date: 2008-07-09T12:22:50-07:00 List-Id: On Jul 9, 12:03 pm, Anh Vo wrote: > On Jul 9, 9:52 am, jujo...@googlemail.com wrote: > > > > > Dear All, > > > I'm tying to print variables of a defined modular type to the standard > > io and a file. > > The type I'm working with is: type Unsigned is mod 2**64; > > > Therefore I define a modular_io package to do this: > > package mio is new ada.text_io.modular_io(usigned); > > > However, when compile my little test program (using gnatmake -gnato), > > the compiler tells me that a "Constraint Error" will be raised at > > runtime. So I tried it with only 63 bit (mod 2**63), which works fine > > with the GNAT 4.3.1 (20080420) on a 32bit Ubuntu-Linux machine. > > > ----------- test program ----------- > > with ada.text_io; use ada.text_io; > > procedure test is > > type Unsigned is mod 2**64; > > package M_IO is new Ada.Text_IO.Modular_IO (Unsigned); > > u : Unsigned := -1; > > begin > > m_io.put(Item => u, Width => 20, Base => 16); > > end; > > ----------------------------------------- > > > I guess that this is a bug. However, what can I do instead of this, to > > get 64 bit words printed as hex, octal and binary? > > If you make u a constant Unsigned, it works as intended. Is it a bug > as far as GNAT is concerned? I am not so sure about it. I need to > check the LRM thouroughly before drawing my conclusion. This works for me: with ada.text_io; use ada.text_io; procedure test is type Unsigned is mod 2**64; function Foo return Unsigned is begin return -1; end Foo; package M_IO is new Ada.Text_IO.Modular_IO (Unsigned); u : Unsigned; begin u := Foo; m_io.put(Item => u, Width => 20, Base => 16); end; Not only does this not display a warning about Constraint_Error, it also doesn't raise Constraint_Error when it's run (and it displays the correct output). But replacing "u := Foo" with "u := -1" or "u := Unsigned'Last" does display the warning, and it does raise Constraint_Error at runtime, presumably because the compiler is doing some value following and has gotten it into its head that Unsigned'Last is out of range for the parameter of Put. No need to check the RM on this one: it's just a bug, period. But this may give the original poster an idea of a workaround. -- Adam