comp.lang.ada
 help / color / mirror / Atom feed
* Exceptions in GNAT
@ 2002-06-02 11:01 David Rasmussen
  2002-06-02 11:04 ` David Rasmussen
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: David Rasmussen @ 2002-06-02 11:01 UTC (permalink / raw)


I am learning Ada, and in one exercise I am told to find out how large 
and integer I can use on my system, before it overflows. The exercise 
just tells me to add two larger and larger numbers and see when an 
exception occurs. I have just compiled my program with gnatmake with no 
options, and I am using gcc 3.1 . When the numbers get large enough, the 
result is just a negative number because of wrap-around. Shouldn't I get 
an exception, unless I turn it off? How do I compile for with most 
checks for debug builds, and how do I compile with everything turned off 
for performance intensive release builds?

/David




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

* Re: Exceptions in GNAT
  2002-06-02 11:01 Exceptions in GNAT David Rasmussen
@ 2002-06-02 11:04 ` David Rasmussen
  2002-06-02 12:36   ` Preben Randhol
  2002-06-02 12:39   ` Jeffrey Creem
  2002-06-02 12:26 ` David C. Hoos, Sr.
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 10+ messages in thread
From: David Rasmussen @ 2002-06-02 11:04 UTC (permalink / raw)


David Rasmussen wrote:
> I am learning Ada, and in one exercise I am told to find out how large 
> and integer I can use on my system, before it overflows. The exercise 
> just tells me to add two larger and larger numbers and see when an 
> exception occurs. I have just compiled my program with gnatmake with no 
> options, and I am using gcc 3.1 . When the numbers get large enough, the 
> result is just a negative number because of wrap-around. Shouldn't I get 
> an exception, unless I turn it off? How do I compile for with most 
> checks for debug builds, and how do I compile with everything turned off 
> for performance intensive release builds?
> 
> /David
> 

D'oh.... This is weird:

Enter two integers: 2100000000 0
The sum is 2100000000
david@amadeus-T23:~/src/Ada/Ex21$ ./sum
Enter two integers: 2200000000 0


raised ADA.IO_EXCEPTIONS.DATA_ERROR : a-tiinio.adb:91 instantiated at 
a-inteio.ads:20
david@amadeus-T23:~/src/Ada/Ex21$ ./sum
Enter two integers: 2147483648 0


raised ADA.IO_EXCEPTIONS.DATA_ERROR : a-tiinio.adb:91 instantiated at 
a-inteio.ads:20
david@amadeus-T23:~/src/Ada/Ex21$ ./sum
Enter two integers: 2147483647 0
The sum is 2147483647
david@amadeus-T23:~/src/Ada/Ex21$ ./sum
Enter two integers: 2147483647 1
The sum is-2147483648
david@amadeus-T23:~/src/Ada/Ex21$ ./sum
Enter two integers: 2147483647 2
The sum is-2147483647
david@amadeus-T23:~/src/Ada/Ex21$

Sometimes there's an exception, and sometimes there isn't... What's 
happening??

/David




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

* Re: Exceptions in GNAT
  2002-06-02 11:01 Exceptions in GNAT David Rasmussen
  2002-06-02 11:04 ` David Rasmussen
@ 2002-06-02 12:26 ` David C. Hoos, Sr.
  2002-06-02 12:28 ` Preben Randhol
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: David C. Hoos, Sr. @ 2002-06-02 12:26 UTC (permalink / raw)



----- Original Message ----- 
From: "David Rasmussen" <pinkfloydhomer@yahoo.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Sunday, June 02, 2002 6:01 AM
Subject: Exceptions in GNAT


> I am learning Ada, and in one exercise I am told to find out how large 
> and integer I can use on my system, before it overflows. The exercise 
> just tells me to add two larger and larger numbers and see when an 
> exception occurs. I have just compiled my program with gnatmake with no 
> options, and I am using gcc 3.1 . When the numbers get large enough, the 
> result is just a negative number because of wrap-around. Shouldn't I get 
> an exception, unless I turn it off? How do I compile for with most 
> checks for debug builds, and how do I compile with everything turned off 
> for performance intensive release builds?
> 
The answers to "how to" questions for GNAT are all contained in the
documentation with GNAT.  If you don't have that, it's downloadable from
ftp.cs.nyu.edu/pub/gnat/3.14p for whatever platform you're using.

E.g., the question about numeric overflow checking is answered by a
search for "numeric overflow" in the GNAT User's Guide.





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

* Re: Exceptions in GNAT
  2002-06-02 11:01 Exceptions in GNAT David Rasmussen
  2002-06-02 11:04 ` David Rasmussen
  2002-06-02 12:26 ` David C. Hoos, Sr.
@ 2002-06-02 12:28 ` Preben Randhol
  2002-06-02 12:39   ` David Rasmussen
  2002-06-02 15:34   ` Simon Wright
  2002-06-02 15:02 ` Robert Dewar
  2002-06-02 20:37 ` Jeffrey Carter
  4 siblings, 2 replies; 10+ messages in thread
From: Preben Randhol @ 2002-06-02 12:28 UTC (permalink / raw)


On Sun, 02 Jun 2002 13:01:21 +0200, David Rasmussen wrote:
> I am learning Ada, and in one exercise I am told to find out how large 
> and integer I can use on my system, before it overflows. The exercise 
> just tells me to add two larger and larger numbers and see when an 
> exception occurs. I have just compiled my program with gnatmake with no 
> options, and I am using gcc 3.1 . When the numbers get large enough, the 
> result is just a negative number because of wrap-around. Shouldn't I get 
> an exception, unless I turn it off? How do I compile for with most 
> checks for debug builds, and how do I compile with everything turned off 
> for performance intensive release builds?

First you made a very good choice with Ada :-) 

I would recommend that you use the gnat 3.14p compiler instead. The
reason is that the gcc 3.1 is very fresh and the compiler is reported to
have some problems. So as you now learn Ada I think you can get
seriously confused if you stumble over these bugs. At least use both and
if you see a difference you can report it.

Which platform do you use?

Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 �For me, Ada95 puts back the joy in programming.�



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

* Re: Exceptions in GNAT
  2002-06-02 11:04 ` David Rasmussen
@ 2002-06-02 12:36   ` Preben Randhol
  2002-06-02 12:39   ` Jeffrey Creem
  1 sibling, 0 replies; 10+ messages in thread
From: Preben Randhol @ 2002-06-02 12:36 UTC (permalink / raw)


On Sun, 02 Jun 2002 13:04:33 +0200, David Rasmussen wrote:
> David Rasmussen wrote:
>> I am learning Ada, and in one exercise I am told to find out how large 
>> and integer I can use on my system, before it overflows. The exercise 
>> just tells me to add two larger and larger numbers and see when an 
>> exception occurs. I have just compiled my program with gnatmake with no 
>> options, and I am using gcc 3.1 . When the numbers get large enough, the 
>> result is just a negative number because of wrap-around. Shouldn't I get 
>> an exception, unless I turn it off? How do I compile for with most 
>> checks for debug builds, and how do I compile with everything turned off 
>> for performance intensive release builds?

use the -gnato

Preben



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

* Re: Exceptions in GNAT
  2002-06-02 11:04 ` David Rasmussen
  2002-06-02 12:36   ` Preben Randhol
@ 2002-06-02 12:39   ` Jeffrey Creem
  1 sibling, 0 replies; 10+ messages in thread
From: Jeffrey Creem @ 2002-06-02 12:39 UTC (permalink / raw)


The only exceptions you are getting are coming from the IO (Data_Error) when
you enter
integers larger then the largest integer. There is explicit code hiding in
the body of text_IO.integer_IOt
that is finding that your data is not appropriate for the type.

What you want is integer overflow checking enabled. GNAT/GCC require a few
options to get
LRM compliant checks "On". GNAT does have many checks enabled by default bit
integer
overflow is not one of them. Check the google history of this group for the
"best" recommended options.

When in the heat of development, I usually use something like :

gnatmake -g -gnato -fstack-check  my_program_name

You need to read through the GNAT users guide to get the rest of the options
for your other questions (since I am not entirely clear how many of these
questions
are part of the assignment and how many are personal knowledge requests).







"David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
news:3CF9FBC1.7040701@yahoo.com...
> David Rasmussen wrote:
> > I am learning Ada, and in one exercise I am told to find out how large
> > and integer I can use on my system, before it overflows. The exercise
> > just tells me to add two larger and larger numbers and see when an
> > exception occurs. I have just compiled my program with gnatmake with no
> > options, and I am using gcc 3.1 . When the numbers get large enough, the
> > result is just a negative number because of wrap-around. Shouldn't I get
> > an exception, unless I turn it off? How do I compile for with most
> > checks for debug builds, and how do I compile with everything turned off
> > for performance intensive release builds?
> >
> > /David
> >
>
> D'oh.... This is weird:
>
> Enter two integers: 2100000000 0
> The sum is 2100000000
> david@amadeus-T23:~/src/Ada/Ex21$ ./sum
> Enter two integers: 2200000000 0
>
>
> raised ADA.IO_EXCEPTIONS.DATA_ERROR : a-tiinio.adb:91 instantiated at
> a-inteio.ads:20
> david@amadeus-T23:~/src/Ada/Ex21$ ./sum
> Enter two integers: 2147483648 0
>
>
> raised ADA.IO_EXCEPTIONS.DATA_ERROR : a-tiinio.adb:91 instantiated at
> a-inteio.ads:20
> david@amadeus-T23:~/src/Ada/Ex21$ ./sum
> Enter two integers: 2147483647 0
> The sum is 2147483647
> david@amadeus-T23:~/src/Ada/Ex21$ ./sum
> Enter two integers: 2147483647 1
> The sum is-2147483648
> david@amadeus-T23:~/src/Ada/Ex21$ ./sum
> Enter two integers: 2147483647 2
> The sum is-2147483647
> david@amadeus-T23:~/src/Ada/Ex21$
>
> Sometimes there's an exception, and sometimes there isn't... What's
> happening??
>
> /David
>





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

* Re: Exceptions in GNAT
  2002-06-02 12:28 ` Preben Randhol
@ 2002-06-02 12:39   ` David Rasmussen
  2002-06-02 15:34   ` Simon Wright
  1 sibling, 0 replies; 10+ messages in thread
From: David Rasmussen @ 2002-06-02 12:39 UTC (permalink / raw)


Preben Randhol wrote:
> On Sun, 02 Jun 2002 13:01:21 +0200, David Rasmussen wrote:
> 
>>I am learning Ada, and in one exercise I am told to find out how large 
>>and integer I can use on my system, before it overflows. The exercise 
>>just tells me to add two larger and larger numbers and see when an 
>>exception occurs. I have just compiled my program with gnatmake with no 
>>options, and I am using gcc 3.1 . When the numbers get large enough, the 
>>result is just a negative number because of wrap-around. Shouldn't I get 
>>an exception, unless I turn it off? How do I compile for with most 
>>checks for debug builds, and how do I compile with everything turned off 
>>for performance intensive release builds?
> 
> 
> First you made a very good choice with Ada :-) 
> 

I think so too :)

> I would recommend that you use the gnat 3.14p compiler instead. The
> reason is that the gcc 3.1 is very fresh and the compiler is reported to

OK, I have both of them installed.

> have some problems. So as you now learn Ada I think you can get
> seriously confused if you stumble over these bugs. At least use both and
> if you see a difference you can report it.
>

I will try it.

> Which platform do you use?
> 

Linux. More precisely, Debian.

/David




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

* Re: Exceptions in GNAT
  2002-06-02 11:01 Exceptions in GNAT David Rasmussen
                   ` (2 preceding siblings ...)
  2002-06-02 12:28 ` Preben Randhol
@ 2002-06-02 15:02 ` Robert Dewar
  2002-06-02 20:37 ` Jeffrey Carter
  4 siblings, 0 replies; 10+ messages in thread
From: Robert Dewar @ 2002-06-02 15:02 UTC (permalink / raw)


David Rasmussen <pinkfloydhomer@yahoo.com> wrote in message news:<3CF9FB01.2070101@yahoo.com>...
> How do I compile for with most checks for debug builds, 
> and how do I compile with everything turned off 
> for performance intensive release builds?

As Jack Point says in "Yeomen of the Guard" (from memory
so it is undoubtedly paraphrased and not 100% Gilbert verbatim :-)

"I shall teach you my best jokes quips and conundrums, nay
I shall do more, I shall reveal the source whence I got
them"

The answer to these and all such questions is in the
GNAT users guide. It is a mistake to try using GNAT without
reading any documentation. That being said, the users guide
is a large document and you definitely do NOT need to read
it all before setting finger to keyboard. What you *should*
read is the summary of switches, since there is a lot of
useful material there. 

A simple way of getting a list of compiler options with
brief descriptions is to do gnatmake with no arguments.
They you can look down the list of -gnat switches with
one line descriptions. This will answer the two specific
questions you asked, as well as tell you about lots of
other useful switches (e.g. I think that most beginners
should use -gnatv if not -gnatl).



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

* Re: Exceptions in GNAT
  2002-06-02 12:28 ` Preben Randhol
  2002-06-02 12:39   ` David Rasmussen
@ 2002-06-02 15:34   ` Simon Wright
  1 sibling, 0 replies; 10+ messages in thread
From: Simon Wright @ 2002-06-02 15:34 UTC (permalink / raw)


Preben Randhol <randhol+abuse@pvv.org> writes:

> I would recommend that you use the gnat 3.14p compiler instead. The
> reason is that the gcc 3.1 is very fresh and the compiler is
> reported to have some problems. So as you now learn Ada I think you
> can get seriously confused if you stumble over these bugs. At least
> use both and if you see a difference you can report it.

Robert Dewar said that there are problems shown by the internal ACT
test suite, but I have to say I haven't found anything yet .. and I
don't recall any problem reports to the gcc mailing list, there are
maybe a couple of open GNATS PRs .. I'm using it for the Booch
Components, no problems yet (well, one perhaps, but it's also in
3.14p, and I'm not at all sure it's a bug)



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

* Re: Exceptions in GNAT
  2002-06-02 11:01 Exceptions in GNAT David Rasmussen
                   ` (3 preceding siblings ...)
  2002-06-02 15:02 ` Robert Dewar
@ 2002-06-02 20:37 ` Jeffrey Carter
  4 siblings, 0 replies; 10+ messages in thread
From: Jeffrey Carter @ 2002-06-02 20:37 UTC (permalink / raw)


David Rasmussen wrote:
> 
> I am learning Ada, and in one exercise I am told to find out how large
> and integer I can use on my system, before it overflows. The exercise
> just tells me to add two larger and larger numbers and see when an
> exception occurs. I have just compiled my program with gnatmake with no
> options, and I am using gcc 3.1 . When the numbers get large enough, the
> result is just a negative number because of wrap-around. Shouldn't I get
> an exception, unless I turn it off? How do I compile for with most
> checks for debug builds, and how do I compile with everything turned off
> for performance intensive release builds?

By now you've learned that overflow checking is off in GNAT by default,
and how to turn it on.

But your program won't tell you how large an integer you can use on your
system. That information is given by the constant System.Max_Int. Your
program will tell you the largest value of type Integer you can use on
your system, but that can be determined faster from Integer'Last.

The point is that the range of type Integer need not be as large as the
range of the largest possible integer type, System.Min_Int ..
System.Max_Int. For every version of GNAT that I've used, type Integer
is 32 bits, but the largest possible integer type is 64 bits.

-- 
Jeff Carter
"Son of a window-dresser."
Monty Python & the Holy Grail



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

end of thread, other threads:[~2002-06-02 20:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-02 11:01 Exceptions in GNAT David Rasmussen
2002-06-02 11:04 ` David Rasmussen
2002-06-02 12:36   ` Preben Randhol
2002-06-02 12:39   ` Jeffrey Creem
2002-06-02 12:26 ` David C. Hoos, Sr.
2002-06-02 12:28 ` Preben Randhol
2002-06-02 12:39   ` David Rasmussen
2002-06-02 15:34   ` Simon Wright
2002-06-02 15:02 ` Robert Dewar
2002-06-02 20:37 ` Jeffrey Carter

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