From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: Getting started with Ada: Runtime exceptions?
Date: Wed, 28 Nov 2001 01:29:05 GMT
Date: 2001-11-28T01:29:05+00:00 [thread overview]
Message-ID: <3C043DC5.96DF5978@acm.org> (raw)
In-Reply-To: 3e076d85.0111271647.338f33d@posting.google.com
Dick Rumsfeld wrote:
>
> Hello all,
> I've just today started to learn Ada. In Section 1.4 of the online
> tutorial I am learning from,
> http://www.adahome.com/Tutorials/Lovelace/s1sf.htm
> it is stated that the below program, when run, will print 2^n for each
> n starting with n=0, until an overflow occurs, at which time the
> program will automatically halt with a message stating an exception
> occured. Well, when I compiled and ran the below program using
> "gnatmake" (which I've just downloaded for my Linux distribution), it
> gives the following output:
>
> 1
> 2
> 4
> 8
> [...output elided...]
> 536870912
> 1073741824
> -2147483648
> 0
> 0
> 0
> ...
A dirty little secret about GNAT is that integer overflow checking is
OFF by default, as you discovered. If you had read the Secret
Documentation for GNAT, you'd know that you turn it ON with the switch
-gnato
in which case your program should output
...
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824
raised CONSTRAINT_ERROR : compute.adb:9
which is much less C-like than your experience. I hope this foible of
GNAT will not put you off Ada.
This default was chosen because, IIRC, in GNAT's early days integer
overflow checking was very expensive on some platforms. I don't know if
that's still the case, but modern processors are so much faster than
those of GNAT's early days that there are probably few situations in
which it makes a difference, so this is probably still the default only
for compatibility reasons. I certainly always turn overflow checking on
when using GNAT, and have never found it too slow.
--
Jeff Carter
"I unclog my nose towards you."
Monty Python & the Holy Grail
prev parent reply other threads:[~2001-11-28 1:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-28 0:47 Getting started with Ada: Runtime exceptions? Dick Rumsfeld
2001-11-28 1:29 ` Jeffrey Carter [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