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,FREEMAIL_FROM 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 Path: g2news1.google.com!postnews.google.com!m44g2000hsc.googlegroups.com!not-for-mail From: jujosei@googlemail.com Newsgroups: comp.lang.ada Subject: Re: Problem using Ada.Text_IO.Modular_IO Date: Thu, 10 Jul 2008 08:00:35 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4837cfb9-bb74-44dd-8803-9289c51bb651@m44g2000hsc.googlegroups.com> References: <4eab7055-df3d-4d56-87da-8248829da1da@26g2000hsk.googlegroups.com> NNTP-Posting-Host: 141.54.138.13 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1215702035 13790 127.0.0.1 (10 Jul 2008 15:00:35 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 10 Jul 2008 15:00:35 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m44g2000hsc.googlegroups.com; posting-host=141.54.138.13; posting-account=dETwSAoAAAD4NxjMOBddsi-x6ff1r0M6 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1083 Date: 2008-07-10T08:00:35-07:00 List-Id: On Jul 9, 11:50=A0pm, Adam Beneschan 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 > > =A0 =A0 =A0 =A0 type Unsigned is mod 2**64; > > =A0 =A0 =A0 =A0 package M_IO is new Ada.Text_IO.Modular_IO (Unsigned); > > =A0 =A0 =A0 =A0 u : Unsigned :=3D -1; > > begin > > =A0 =A0 =A0 =A0 m_io.put(Item =3D> =A0u, Width =3D> =A020, Base =A0=3D>= 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: > > =A0 pragma Volatile (u); > > This prevents the compiler from thinking it knows what "u" is going to > hold, and everything works fine. =A0Of 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. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- Adam Thank you Adam, pragma Volatile (u); is perfect! Cheers Julian