comp.lang.ada
 help / color / mirror / Atom feed
* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00 Help ... CONSTRAINT_ERROR jxredi
  1999-11-30  0:00 ` Preben Randhol
@ 1999-11-30  0:00 ` reason67
  1999-11-30  0:00   ` Preben Randhol
  1999-12-02  0:00 ` Stephen Leake
  1999-12-06  0:00 ` skamn
  3 siblings, 1 reply; 10+ messages in thread
From: reason67 @ 1999-11-30  0:00 UTC (permalink / raw)


In article <81vfu6$sem$1@tobruk.sydney.gecm.com>,
  "jxredi" <jxredi@gecms.com.au> wrote:
>
> Hi,
> I was wondering if you could help me out with this problem (using
ADA83) :
>
> package R_IO is new TEXT_IO.FLOAT_IO(Float);
> NUM : STRING :=   "hi there";
> FNUM : Float := 0.75;
> R_IO.PUT(NUM,FNUM);   -- this is where the problem is ... but what's
wrong
> ??
>
> ------------
> RUN-TIME ERROR :     "constraint_error".

The code you posted would not compile:
      NUM : STRING := "hi there";
      The string length of a variable has to be defined. If this was a
constant, it would work as it would get the length from the string, but
as a variable, you would have to say (1 .. 8) after the String. Assuming
a typo and it is (1 .. 8), I know the problem:

R_IO.PUT (NUM, FNUM);

Is this call:

procedure Put(To   : out String;
              Item : in Num;
              Aft  : in Field := Default_Aft;
              Exp  : in Field := Default_Exp);


Num is 8 characters long and if you are using float, most likely that is
a single precisions IEEE floating point (have to know your compiler to
be certain as it is implementation defined) and without specifying the
aft or exponent it will try to write a 6 digit string with 1 decimal and
3 characters for exponent and 1 character for sign in the form
"sd.dddddEnn" which is longer than 8 characters. That is causing your
constaint error. Change Num to String (1 .. 20) and it should work. Once
it does see how many digits are displayed (probably 6) and how long the
exponent is and add 4 characters and that is the minimum size string you
should use.

Hope this helps.
---
Jeffrey Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00   ` Preben Randhol
  1999-11-30  0:00     ` reason67
@ 1999-11-30  0:00     ` Robert A Duff
  1999-11-30  0:00       ` Ted Dennison
  1999-11-30  0:00     ` David C. Hoos, Sr.
  2 siblings, 1 reply; 10+ messages in thread
From: Robert A Duff @ 1999-11-30  0:00 UTC (permalink / raw)


Preben Randhol <randhol@pvv.org> writes:

> reason67@my-deja.com writes:

> |       NUM : STRING := "hi there";
> 
> It compiles under Ada95. Was this changed from Ada83 to Ada95 ?

Yes.  This is legal Ada 95, but was illegal in Ada 83.

- Bob




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00   ` Preben Randhol
@ 1999-11-30  0:00     ` reason67
  1999-11-30  0:00     ` Robert A Duff
  1999-11-30  0:00     ` David C. Hoos, Sr.
  2 siblings, 0 replies; 10+ messages in thread
From: reason67 @ 1999-11-30  0:00 UTC (permalink / raw)


In article <m3emd83rg2.fsf@kiuk0156.chembio.ntnu.no>,
  Preben Randhol <randhol@pvv.org> wrote:
> reason67@my-deja.com writes:
>
> | The code you posted would not compile:
> |       NUM : STRING := "hi there";

> It compiles under Ada95. Was this changed from Ada83 to Ada95 ?

I did not know it was legal in Ada95. I wonder why they changed that. A
String must still have a fixed length, so, like a constant, it must
derive the information from the default value. Thanks for the info.
---
Jeffrey S. Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00     ` Robert A Duff
@ 1999-11-30  0:00       ` Ted Dennison
  0 siblings, 0 replies; 10+ messages in thread
From: Ted Dennison @ 1999-11-30  0:00 UTC (permalink / raw)


In article <wccwvr053qe.fsf@world.std.com>,
  Robert A Duff <bobduff@world.std.com> wrote:
> Preben Randhol <randhol@pvv.org> writes:
>
> > reason67@my-deja.com writes:
>
> > |       NUM : STRING := "hi there";
> >
> > It compiles under Ada95. Was this changed from Ada83 to Ada95 ?
>
> Yes.  This is legal Ada 95, but was illegal in Ada 83.

One of a host of little improvements that make Ada 95 worth the
upgrade, reguardless of wheather you ever use a tagged type or not.
Another good example from the original post is that float'image wasn't
legal either, hence the need to use a Float_IO package. A third good
example from that post is that by default there was no pre-instatiated
version of Float_IO (Ada.Float_Text_IO), hence the need to manually
instantiate Text_IO.Float_IO with Float.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Help ... CONSTRAINT_ERROR
@ 1999-11-30  0:00 jxredi
  1999-11-30  0:00 ` Preben Randhol
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: jxredi @ 1999-11-30  0:00 UTC (permalink / raw)



Hi,
I was wondering if you could help me out with this problem (using ADA83) :

package R_IO is new TEXT_IO.FLOAT_IO(Float);
NUM : STRING :=   "hi there";
FNUM : Float := 0.75;
R_IO.PUT(NUM,FNUM);   -- this is where the problem is ... but what's wrong
??


------------
RUN-TIME ERROR :     "constraint_error".




----
Cheers,
Jxredi.







^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00 Help ... CONSTRAINT_ERROR jxredi
@ 1999-11-30  0:00 ` Preben Randhol
  1999-11-30  0:00 ` reason67
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Preben Randhol @ 1999-11-30  0:00 UTC (permalink / raw)


"jxredi" <jxredi@gecms.com.au> writes:

| Hi,
| I was wondering if you could help me out with this problem (using ADA83) :
| 
| package R_IO is new TEXT_IO.FLOAT_IO(Float);
| NUM : STRING :=   "hi there";
| FNUM : Float := 0.75;
| R_IO.PUT(NUM,FNUM);   -- this is where the problem is ... but what's wrong
| ??

R_IO takes float but not a string.

I would have done this: (I only know Ada95 though)

Text_IO.Put(Num);
R_IO.Put(FNUM);

Or I would have done:

Text_IO.Put(Num & Float'Image(FNUM))

NB: Note that I only know some Ada95, so if this doesn't work with
Ada83 it is me that is wrong not the compiler :-)
-- 
Preben Randhol -- [randhol@pvv.org] -- [http://www.pvv.org/~randhol/]     
         "Det eneste trygge stedet i verden er inne i en fortelling." 
                                                      -- Athol Fugard




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00 ` reason67
@ 1999-11-30  0:00   ` Preben Randhol
  1999-11-30  0:00     ` reason67
                       ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Preben Randhol @ 1999-11-30  0:00 UTC (permalink / raw)


reason67@my-deja.com writes:

| The code you posted would not compile:
|       NUM : STRING := "hi there";
|       The string length of a variable has to be defined. If this was a
| constant, it would work as it would get the length from the string, but
| as a variable, you would have to say (1 .. 8) after the String. Assuming

It compiles under Ada95. Was this changed from Ada83 to Ada95 ?

-- 
Preben Randhol -- [randhol@pvv.org] -- [http://www.pvv.org/~randhol/]     
         "Det eneste trygge stedet i verden er inne i en fortelling." 
                                                      -- Athol Fugard




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00   ` Preben Randhol
  1999-11-30  0:00     ` reason67
  1999-11-30  0:00     ` Robert A Duff
@ 1999-11-30  0:00     ` David C. Hoos, Sr.
  2 siblings, 0 replies; 10+ messages in thread
From: David C. Hoos, Sr. @ 1999-11-30  0:00 UTC (permalink / raw)



Preben Randhol <randhol@pvv.org> wrote in message
news:m3emd83rg2.fsf@kiuk0156.chembio.ntnu.no...
> reason67@my-deja.com writes:
>
> | The code you posted would not compile:
> |       NUM : STRING := "hi there";
> |       The string length of a variable has to be defined. If this was a
> | constant, it would work as it would get the length from the string, but
> | as a variable, you would have to say (1 .. 8) after the String. Assuming
>
> It compiles under Ada95. Was this changed from Ada83 to Ada95 ?
>
Yes it was.  In Ada83, you could only declare a constant string this way.







^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00 Help ... CONSTRAINT_ERROR jxredi
  1999-11-30  0:00 ` Preben Randhol
  1999-11-30  0:00 ` reason67
@ 1999-12-02  0:00 ` Stephen Leake
  1999-12-06  0:00 ` skamn
  3 siblings, 0 replies; 10+ messages in thread
From: Stephen Leake @ 1999-12-02  0:00 UTC (permalink / raw)


"jxredi" <jxredi@gecms.com.au> writes:

> Hi,
> I was wondering if you could help me out with this problem (using ADA83) :
> 
> package R_IO is new TEXT_IO.FLOAT_IO(Float);
> NUM : STRING :=   "hi there";
> FNUM : Float := 0.75;
> R_IO.PUT(NUM,FNUM);   -- this is where the problem is ... but what's wrong
> ??

I cleaned this up as:

with Text_IO;
procedure Jxredi is
   package R_IO is new Text_IO.Float_IO (Float);
   NUM : STRING :=   "hi there";
   FNUM : Float := 0.75;
begin
   R_IO.Put (NUM, FNUM);
end Jxredi;

compiling and running with GNAT gives:

./jxredi.exe  > jxredi.out

raised ADA.IO_EXCEPTIONS.LAYOUT_ERROR : a-tiflau.adb:218

Since GNAT comes with source code, I looked at 'a-tiflau.adb:218'
(cool!). The problem is that the string NUM is too short for the
canonical representation of FNUM.

Note that the call to R_IO.Put writes the image of FNUM into the
string NUM; is that what you wanted it to do? If you are used to C
printf, you probably wanted the following output:

hello there 0.75

Here's a program that does that:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
procedure Jxredi is
   NUM : String := "hello there";
   FNUM : Float := 0.75;
begin
   Put (NUM);
   Put (FNUM, Fore => 2, Aft => 2, Exp => 0);
end Jxredi;

./jxredi.exe 
hello there 0.75


-- Stephe




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Help ... CONSTRAINT_ERROR
  1999-11-30  0:00 Help ... CONSTRAINT_ERROR jxredi
                   ` (2 preceding siblings ...)
  1999-12-02  0:00 ` Stephen Leake
@ 1999-12-06  0:00 ` skamn
  3 siblings, 0 replies; 10+ messages in thread
From: skamn @ 1999-12-06  0:00 UTC (permalink / raw)


In article <81vfu6$sem$1@tobruk.sydney.gecm.com>,
  "jxredi" <jxredi@gecms.com.au> wrote:
>
> Hi,
> I was wondering if you could help me out with this problem (using
ADA83) :
>
> package R_IO is new TEXT_IO.FLOAT_IO(Float);
> NUM : STRING :=   "hi there";
> FNUM : Float := 0.75;
> R_IO.PUT(NUM,FNUM);   -- this is where the problem is ... but what's
wrong
> ??
>
> ------------

> RUN-TIME ERROR :     "constraint_error".
>
> ----
> Cheers,
> Jxredi.
>
>This should work:
with text_IO;
procedure try is
        package Float_IO is new Text_IO.Float_IO (num => float);
        NUM : string (1..8) := "hi there";
        FNUM : float := 0.75;
begin
        Text_IO.put (NUM);
        Text_IO.put(" ");
        Float_IO.put (FNUM, fore => 1, aft => 2, Exp => 0);
end try;





Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1999-12-06  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-30  0:00 Help ... CONSTRAINT_ERROR jxredi
1999-11-30  0:00 ` Preben Randhol
1999-11-30  0:00 ` reason67
1999-11-30  0:00   ` Preben Randhol
1999-11-30  0:00     ` reason67
1999-11-30  0:00     ` Robert A Duff
1999-11-30  0:00       ` Ted Dennison
1999-11-30  0:00     ` David C. Hoos, Sr.
1999-12-02  0:00 ` Stephen Leake
1999-12-06  0:00 ` skamn

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