From: adam@irvine.com (Adam Beneschan)
Subject: Re: GNAT won't link on "warning"
Date: 30 Nov 2004 11:38:15 -0800
Date: 2004-11-30T11:38:15-08:00 [thread overview]
Message-ID: <b4682ab7.0411301138.4006f462@posting.google.com> (raw)
In-Reply-To: 3664370.5jO7nDmgDP@linux1.krischik.com
Martin Krischik <martin@krischik.com> wrote in message news:<3664370.5jO7nDmgDP@linux1.krischik.com>...
> Hello,
>
> For demonstation purpose I wanted to write a program which will raise an
> exception on converting some data:
>
> with Ada.Text_IO;
>
> procedure Convert_Checked
> is
> type Short_Short_Integer is range -(2**7) .. +(2**7-1);
> type Byte is mod 2**8;
>
> package T_IO renames Ada.Text_IO;
> package M_IO is new Ada.Text_IO.Modular_IO (Byte);
>
> A : constant Short_Short_Integer := -1;
> B : constant Byte := Byte (A);
> begin
> T_IO.Put ("B = ");
> M_IO.Put (
> Item => B,
> Width => 5,
> Base => 10);
> end Convert_Checked;
>
> When I compile the demo I get:
>
> convert_checked.adb:12:40: value not in range of type "Byte" defined at line
> 6
> convert_checked.adb:12:40: static expression raises "Constraint_Error"
>
> It is my intention to use a value which is not in range of type "Byte" and
> "Constraint_Error" is precicly what I want to demonstate.
See RM 4.9(33-34). If you make A a variable (not a constant), it
should compile (I haven't tried it).
-- Adam
prev parent reply other threads:[~2004-11-30 19:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-29 9:45 GNAT won't link on "warning" Martin Krischik
2004-11-28 19:37 ` Manuel G. R.
2004-11-29 12:37 ` David C. Hoos, Sr.
2004-11-29 16:52 ` Martin Krischik
2004-11-29 15:42 ` Sandro Magi
2004-11-30 19:38 ` Adam Beneschan [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox