comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: What does this code mean?
Date: Wed, 07 Jan 2015 21:37:08 -0700
Date: 2015-01-07T21:37:08-07:00	[thread overview]
Message-ID: <XPnrw.219077$pr4.10387@fx26.iad> (raw)
In-Reply-To: <68ac5df1-21ab-4b8e-acae-819c78fe8536@googlegroups.com>

On 07-Jan-15 20:53, John Smith wrote:
>
> My question is why is this code written this way?
>  Is it just plain wrong or am I missing some concept that the author(s)
> tried to get across that I'm missing?
>

I think it's wrong -- the "package I_IO is new Ada (Short);" is syntax 
for instantiating a generic package... noticing the space-comma, I think 
there might have been a transcription error -- it is likely this is what 
was meant:


    With Ada.Text_IO;
    procedure Convert_Checked is
       type Short is range -128 .. +127;
       type Byte is mod 256;

       package T_IO renames Ada.Text_IO;
       package I_IO is new Ada.Text_IO.Integer_IO (Short);
       package M_IO is new Ada.Text_IO.Modular_IO (Byte);

       A : Short := -1;
       B : Byte;
    begin
       B := Byte (A); -- range check will lead to Constraint_Error

       T_IO.Put("A = ");
       I_IO.Put(Item  => A,
                Width => 5,
                Base  => 10);
       T_IO.Put(", B = ");
       M_IO.Put(Item  => B,
                Width => 5,
                Base  => 10);
    end Convert_Checked;

  reply	other threads:[~2015-01-08  4:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-08  3:53 What does this code mean? John Smith
2015-01-08  4:37 ` Shark8 [this message]
2015-01-08  9:13   ` Simon Wright
2015-01-08 16:44     ` Dirk Heinrichs
2015-01-08 18:42 ` AdaMagica
2015-01-08 18:45   ` AdaMagica
2015-01-10 21:37     ` John Smith
replies disabled

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