comp.lang.ada
 help / color / mirror / Atom feed
* Get Integer into Enumeration_IO doesn't work
@ 2002-11-16 10:17 Amir Shaked
  2002-11-16 11:13 ` David C. Hoos, Sr.
  2002-11-17  8:38 ` Dr. Michael Paus
  0 siblings, 2 replies; 5+ messages in thread
From: Amir Shaked @ 2002-11-16 10:17 UTC (permalink / raw)


Hello,

The following code compiles and links
but fails on DATA_ERROR in run-time.
Can you tell me why?

with Text_IO;
procedure PrintInt
is
   Num  : Integer;
   package EnumIO is new Text_IO.Enumeration_IO(Integer);
begin
   Text_IO.Put_Line ("Enter Num:");
   EnumIO.Get (Num);
end PrintInt;



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

* Re: Get Integer into Enumeration_IO doesn't work
  2002-11-16 10:17 Amir Shaked
@ 2002-11-16 11:13 ` David C. Hoos, Sr.
  2002-11-17  8:38 ` Dr. Michael Paus
  1 sibling, 0 replies; 5+ messages in thread
From: David C. Hoos, Sr. @ 2002-11-16 11:13 UTC (permalink / raw)


Why are you using Enumeration_IO to read numbers?

Enumerations are types like this:
type Color is (Red, Orange, Yellow, Green, Blue, Purple);

Then, an Enumeration_IO package instantiated for the type
Color would read the string "orange", and translate it to
the  Orange enumeration value which is represented in memory
by the binary number 1. (0 for red, 2 for yellow, etc.).

To input and output integers, you should use an instantiation
of Ada.Text_IO.Integer_IO.
 
----- Original Message ----- 
From: "Amir Shaked" <amir.shaked@ca.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: November 16, 2002 4:17 AM
Subject: Get Integer into Enumeration_IO doesn't work


> Hello,
> 
> The following code compiles and links
> but fails on DATA_ERROR in run-time.
> Can you tell me why?
> 
> with Text_IO;
> procedure PrintInt
> is
>    Num  : Integer;
>    package EnumIO is new Text_IO.Enumeration_IO(Integer);
> begin
>    Text_IO.Put_Line ("Enter Num:");
>    EnumIO.Get (Num);
> end PrintInt;
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 




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

* Re: Get Integer into Enumeration_IO doesn't work
  2002-11-16 10:17 Amir Shaked
  2002-11-16 11:13 ` David C. Hoos, Sr.
@ 2002-11-17  8:38 ` Dr. Michael Paus
  1 sibling, 0 replies; 5+ messages in thread
From: Dr. Michael Paus @ 2002-11-17  8:38 UTC (permalink / raw)


Amir Shaked wrote:
> Hello,
> 
> The following code compiles and links
> but fails on DATA_ERROR in run-time.
> Can you tell me why?
> 
> with Text_IO;
> procedure PrintInt
> is
>    Num  : Integer;
>    package EnumIO is new Text_IO.Enumeration_IO(Integer);
> begin
>    Text_IO.Put_Line ("Enter Num:");
>    EnumIO.Get (Num);
> end PrintInt;

If you do not need any specific formatting you can simply write:

with Text_IO;
procedure PrintInt
is
    Num  : Integer := 4711; -- You have to assign some value
begin
    Text_IO.Put_Line ("Enter Num:" & Integer'Image(Num));
end PrintInt;

In this case you do not need any instantiations at all.

Michael




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

* Re: Get Integer into Enumeration_IO doesn't work
@ 2002-11-18  6:38 Grein, Christoph
  2002-11-18 14:28 ` Peter Richtmyer
  0 siblings, 1 reply; 5+ messages in thread
From: Grein, Christoph @ 2002-11-18  6:38 UTC (permalink / raw)


> The following code compiles and links
> but fails on DATA_ERROR in run-time.
> Can you tell me why?
> 
> with Text_IO;
> procedure PrintInt
> is
>    Num  : Integer;
>    package EnumIO is new Text_IO.Enumeration_IO(Integer);
> begin
>    Text_IO.Put_Line ("Enter Num:");
>    EnumIO.Get (Num);
> end PrintInt;

While Integer is a discrete type and therefore allowed as an actual parameter to 
Text_IO.Enumeration_IO, this package is meant to be instantiated with 
enumeration types only.



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

* Re: Get Integer into Enumeration_IO doesn't work
  2002-11-18  6:38 Get Integer into Enumeration_IO doesn't work Grein, Christoph
@ 2002-11-18 14:28 ` Peter Richtmyer
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Richtmyer @ 2002-11-18 14:28 UTC (permalink / raw)


"Grein, Christoph" <christoph.grein@eurocopter.com> wrote in message news:<mailman.1037601904.17138.comp.lang.ada@ada.eu.org>...
> While Integer is a discrete type and therefore allowed as an actual parameter to 
> Text_IO.Enumeration_IO, this package is meant to be instantiated with 
> enumeration types only.

In my experience (it may depend upon the compiler) the compiler would 
allow me to instantiate an integer-type with enumeration_io, but it 
would raise an exception on a *get*. Obviously, it would be better if
the compiler caught the error when compiling. Obviously, it would be
even better if I did not code the error  :-)

happy coding...
Peter



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

end of thread, other threads:[~2002-11-18 14:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-18  6:38 Get Integer into Enumeration_IO doesn't work Grein, Christoph
2002-11-18 14:28 ` Peter Richtmyer
  -- strict thread matches above, loose matches on Subject: below --
2002-11-16 10:17 Amir Shaked
2002-11-16 11:13 ` David C. Hoos, Sr.
2002-11-17  8:38 ` Dr. Michael Paus

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