comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Simple program to find average of 3 numbers
Date: Thu, 10 Jul 2003 19:56:36 -0500
Date: 2003-07-10T19:56:36-05:00	[thread overview]
Message-ID: <vgs2n636ssva7@corp.supernews.com> (raw)
In-Reply-To: 3F0D8A17.2010407@attbi.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1620 bytes --]

> Matthew Heaney wrote:
> > With respect to the base range of the type, how do the declarations
> >
> >    type T is new Integer range 1 .. 100;
> >    type T is range 1 .. 100;
> >
> > differ from one another?

For the first, the base type is derived from Integer'Base. So T'Base'First =
Integer'Base'First.

OTOH, all we know about the second T is that T'First <= -100, and T'Last >=
100. (Generally, it is some power of two). Thus, the second gives more power
to the compiler, and thus is preferred.

For instance, Janus/Ada has historically used Integer'Size = 16 (that kept
all of our compilers compatible -- probably a bad choice, but it is
impossible to change without breaking a lot of user code).
    type T1 is Integer range 0 .. 100_000;
       -- Raises Constraint_Error on most versions of Janus/Ada; will work
on GNAT, etc.
    type T2 is range 0 .. 100_000;
       -- Works fine on all modern versions of Janus/Ada.

                        Randy.




> Look at the output from the program I provided.  In the first case, the
> base type has the same characteristics as Integer'Base.  In the second
> example, look at the results of the program I ran.  The compiler can
> choose any predefined integer type for the base type.  In this case,
> GNAT choose one with a range -128..127.
> --
>
>                                                         Robert I. Eachus
>
> �In an ally, considerations of house, clan, planet, race are
> insignificant beside two prime questions, which are: 1. Can he shoot? 2.
> Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and
> Steve Miller.
>





  reply	other threads:[~2003-07-11  0:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-04  5:01 Simple program to find average of 3 numbers prashna
2003-07-04  5:22 ` John R. Strohm
2003-07-04  5:34   ` Cephus�
2003-07-04  9:54     ` Tarjei T. Jensen
2003-07-05 17:49       ` Cephus�
2003-07-04  5:33 ` Robert I. Eachus
2003-07-04  8:37   ` Stuart Palin
2003-07-05 10:06     ` Preben Randhol
2003-07-04  5:39 ` tmoran
2003-07-04  9:28   ` prashna
2003-07-04 11:02     ` Stuart Palin
2003-07-04 16:20     ` Pascal Obry
2003-07-05  1:25       ` Robert I. Eachus
     [not found]     ` <1e3ht-ig4.ln1@beastie.ix.netcom.com>
2003-07-04 21:17       ` Jeffrey Creem
2003-07-05  5:07         ` Anders Wirzenius
2003-07-05 14:39 ` Marqmc5
2003-07-06  3:47 ` g_ak
2003-07-08  5:06   ` prashna
2003-07-09 15:25     ` Matthew Heaney
2003-07-09 21:38       ` Robert I. Eachus
2003-07-10 13:52         ` Matthew Heaney
2003-07-10 15:46           ` Robert I. Eachus
2003-07-11  0:56             ` Randy Brukardt [this message]
2003-07-11 21:54           ` Robert A Duff
2003-07-11 21:50         ` Robert A Duff
2003-07-11 23:32           ` Robert I. Eachus
2003-07-10  4:55       ` Simon Wright
  -- strict thread matches above, loose matches on Subject: below --
2003-07-09  6:24 christoph.grein
replies disabled

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