From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Question about base types
Date: 1997/01/30
Date: 1997-01-30T00:00:00+00:00 [thread overview]
Message-ID: <dewar.854626377@merv> (raw)
In-Reply-To: mheaney-ya023280003001970055250001@news.ni.net
Matthew asks
Can you point out to me where the RM95 states that the "portable range" of
T (our example here) need only be -10 .. 10?
Obviously the base range need only cover the required range of the subtype
being declared. Where can you possibly get any other idea from the RM?
This is sort of a bummer. I had hoped that T'Base would give me something
nearer to System.Max_Int.
Of course not, it would be horribly inefficient on many machines to choose
System.Max_Int as the base type of all integer types. Consider the case of
GNAT where all implementations support at least 64-bits for Max_Int, but
of course on many architectures, 64-bit arithmetic is not available, and
has to be synthesized. You really do NOT want ordinary Integer arithmetic
to have to use inefficient 64-bit arithmetic!
If you want Max_Int, then use Max_Int!
What T'Base gives you is an efficient hardware type big enough to hold
your subtype.
Can I do this implementation below, legally and portably?
function "+" (L, R : Heading) return Heading is
Sum : constant Heading'Base := L + R;
begin
if Sum > Heading'Last then
return Sum - Heading'Last;
else
return Sum;
end if;
end;
No you can't, because there is no guarantee that the range of Heading'Base
exceeds the range of Heading. If you find this a "bummer" you have some
fundamental misconceptions about the type system of Ada.
What you need to do is to define a local subtype large enough to hold the
sum and do conversions appropriately.
A suggestion is to read up on how type declarations work in one of the
good Ada text books (Norman Cohen's book is a good choice if you want
something comprehensive). The RM is NOT a good source to learn basic
stuff like this, you really need to know Ada pretty well before you
can usefully use the RM as a reference source.
next prev parent reply other threads:[~1997-01-30 0:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-01-26 0:00 Question about base types Matthew Heaney
1997-01-27 0:00 ` Robert A Duff
1997-01-30 0:00 ` Matthew Heaney
1997-01-30 0:00 ` Robert Dewar [this message]
1997-01-30 0:00 ` Matthew Heaney
1997-01-30 0:00 ` Matthew Heaney
[not found] ` <EACHUS.97Feb3221558@spectre.mitre.org>
[not found] ` <dewar.855063927@merv>
[not found] ` <EACHUS.97Feb6145918@spectre.mitre.org>
[not found] ` <dewar.855276722@merv>
1997-02-07 0:00 ` Mats Weber
1997-02-08 0:00 ` Robert Dewar
1997-02-10 0:00 ` Mats Weber
1997-02-11 0:00 ` Robert Dewar
[not found] ` <32FB45D4.2160@watson.ibm.com>
1997-02-10 0:00 ` Robert Dewar
1997-02-08 0:00 ` Robert Dewar
1997-02-09 0:00 ` Matthew Heaney
1997-02-09 0:00 ` Robert Dewar
1997-02-09 0:00 ` Matthew Heaney
1997-02-10 0:00 ` Robert Dewar
1997-02-10 0:00 ` Larry Kilgallen
1997-02-11 0:00 ` Robert I. Eachus
1997-02-12 0:00 ` Robert Dewar
1997-01-27 0:00 ` Mats Weber
1997-01-28 0:00 ` Robert A Duff
1997-01-29 0:00 ` Robert Dewar
1997-01-28 0:00 ` Robert I. Eachus
1997-01-28 0:00 ` Mats Weber
1997-01-29 0:00 ` Robert I. Eachus
1997-01-30 0:00 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox