comp.lang.ada
 help / color / mirror / Atom feed
* Re: GNAT won't link on "warning"
  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.
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Manuel G. R. @ 2004-11-28 19:37 UTC (permalink / raw)


Martin Krischik wrote:
  > 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"
> 

GNAT tags by default all the warnings with the string "warning:" so you 
can recognize the errors for its lack of this tag. Alternatively you can 
use -gnatU with gnatmake and gcc:

`-gnatU'
      Tag all error messages with the unique string "error:"



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

* GNAT won't link on "warning"
@ 2004-11-29  9:45 Martin Krischik
  2004-11-28 19:37 ` Manuel G. R.
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Martin Krischik @ 2004-11-29  9:45 UTC (permalink / raw)
  To: GNAT Discussion List

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.

However, GNAT won't link the program. Actually GNAT won't even create an *.o
file. Is this right? Is there an option to force creation?

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: GNAT won't link on "warning"
  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
  3 siblings, 1 reply; 6+ messages in thread
From: David C. Hoos, Sr. @ 2004-11-29 12:37 UTC (permalink / raw)
  To: martin; +Cc: comp.lang.ada

The reason it won't compile is that you caused the constraint
error at compile time.  This is an error and not a warning.

When runtime constraint errors are detected at compile time,
the warning message says "will raise constraint_error."  The
message you received said "raises constraint_error," i.e.
present tense, instead of the future tense warning.

If you do the illegal conversion at run time (i.e. after
the "begin," it will compile and link, with a warning, but
fail at run time.

----- Original Message ----- 
From: "Martin Krischik" <martin@krischik.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 29, 2004 3:45 AM
Subject: GNAT won't link on "warning"


> 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.
> 
> However, GNAT won't link the program. Actually GNAT won't even create an *.o
> file. Is this right? Is there an option to force creation?
> 
> With Regards
> 
> Martin
> 
> -- 
> mailto://krischik@users.sourceforge.net
> http://www.ada.krischik.com
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 
>



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

* Re: GNAT won't link on "warning"
  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 15:42 ` Sandro Magi
  2004-11-30 19:38 ` Adam Beneschan
  3 siblings, 0 replies; 6+ messages in thread
From: Sandro Magi @ 2004-11-29 15:42 UTC (permalink / raw)


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.

GNAT has determined at compile-time that the value is out of range for
the type you specified.

> However, GNAT won't link the program. Actually GNAT won't even create an *.o
> file. Is this right? Is there an option to force creation?

pragma Suppress(Range_Check)

will suppress the run-time checks, but I'm not sure if it wil suppress
compile-time checks. The best way to test run-time exception cases is
to read some data in from some external source (like the command-line
or a file). There are examples to do this on http://www.adapower.com



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

* Re: GNAT won't link on "warning"
  2004-11-29 12:37 ` David C. Hoos, Sr.
@ 2004-11-29 16:52   ` Martin Krischik
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Krischik @ 2004-11-29 16:52 UTC (permalink / raw)


David C. Hoos, Sr. wrote:

> The reason it won't compile is that you caused the constraint
> error at compile time.  This is an error and not a warning.
> 
> When runtime constraint errors are detected at compile time,
> the warning message says "will raise constraint_error."  The
> message you received said "raises constraint_error," i.e.
> present tense, instead of the future tense warning.
> 
> If you do the illegal conversion at run time (i.e. after
> the "begin," it will compile and link, with a warning, but
> fail at run time.

Thanks!

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: GNAT won't link on "warning"
  2004-11-29  9:45 GNAT won't link on "warning" Martin Krischik
                   ` (2 preceding siblings ...)
  2004-11-29 15:42 ` Sandro Magi
@ 2004-11-30 19:38 ` Adam Beneschan
  3 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 2004-11-30 19:38 UTC (permalink / raw)


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



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

end of thread, other threads:[~2004-11-30 19:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox