comp.lang.ada
 help / color / mirror / Atom feed
From: jujosei@googlemail.com
Subject: Re: Problem using Ada.Text_IO.Modular_IO
Date: Thu, 10 Jul 2008 08:00:35 -0700 (PDT)
Date: 2008-07-10T08:00:35-07:00	[thread overview]
Message-ID: <4837cfb9-bb74-44dd-8803-9289c51bb651@m44g2000hsc.googlegroups.com> (raw)
In-Reply-To: ea236c84-6478-458e-a655-64d671cfa52c@i76g2000hsf.googlegroups.com

On Jul 9, 11:50 pm, Adam Beneschan <a...@irvine.com> 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?
>
> 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

Thank you Adam,
pragma Volatile (u); is perfect!

Cheers

Julian



  reply	other threads:[~2008-07-10 15:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-09 16:52 Problem using Ada.Text_IO.Modular_IO jujosei
2008-07-09 19:03 ` Anh Vo
2008-07-09 19:22   ` Adam Beneschan
2008-07-09 21:50 ` Adam Beneschan
2008-07-10 15:00   ` jujosei [this message]
2008-07-10  0:48 ` anon
2008-07-10  1:52   ` Adam Beneschan
2008-07-10  7:25     ` anon
2008-07-10 14:59       ` Adam Beneschan
2008-07-11  0:34         ` anon
2008-07-11  9:49           ` Georg Bauhaus
2008-07-11 10:05             ` christoph.grein
2008-07-11 13:21               ` John McCormick
2008-07-11 12:16             ` anon
2008-07-11 13:26               ` petter_fryklund
2008-07-11 21:10                 ` anon
2008-07-12 10:06                   ` Georg Bauhaus
2008-07-13  0:51                     ` anon
2008-07-13 16:03                     ` Georg Bauhaus
2008-07-14  2:03                       ` anon
2008-07-14 13:12                         ` Georg Bauhaus
2008-07-16  6:16                           ` micronian2
2008-07-16  7:47                             ` anon
2008-07-17 16:33                               ` micronian2
2008-07-14 16:34                       ` micronian2
2008-07-14 17:26                         ` Georg Bauhaus
2008-07-16  6:28                           ` micronian2
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox