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!i76g2000hsf.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 14:50:10 -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 1215640211 32536 127.0.0.1 (9 Jul 2008 21:50:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 9 Jul 2008 21:50:11 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i76g2000hsf.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:1057 Date: 2008-07-09T14:50:10-07:00 List-Id: 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? Here's an even simpler workaround than my last suggestion: After the declaration of "u", just add this: pragma Volatile (u); This prevents the compiler from thinking it knows what "u" is going to hold, and everything works fine. Of course, in real-life code, you're a lot more likely to using "put" on a value that the compiler won't be able to determine at compile time, so the above bug isn't going to appear anyway and you don't need a workaround. -- Adam