comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Question about base types
Date: 1997/01/30
Date: 1997-01-30T00:00:00+00:00	[thread overview]
Message-ID: <E4t0wv.1tu@world.std.com> (raw)
In-Reply-To: EACHUS.97Jan29150858@spectre.mitre.org


In article <EACHUS.97Jan29150858@spectre.mitre.org>,
Robert I. Eachus <eachus@spectre.mitre.org> wrote:
>
>   I said: 
>
>   >   No.  The range of the anonomous type must be at least -15..15, but
>   > the actual range is implementation dependent.
>
>In article <32EE1434.3BB4@elca-matrix.ch> Mats Weber <Mats.Weber@elca-matrix.ch> writes:
>
>   > I think this should be -10 .. 10. Nothing in the RM says it must be a
>   > power of two minus one.

This is correct.  If you say "type T is range 1..10;", then T'Base will
be -10..10, or some range including that.  Period.  In both Ada 83 and
Ada 95.  For efficiency reasons, most compilers will choose a much
larger range, based on some power of 2, and 2's complement arithmetic.
But the only RM requirement here is that T'Base'Range be symmetric about
zero (plus perhaps one extra negative value), and include 1..10.

Sorry, but the stuff below is not correct.

>   Sigh, think of it as a ramification. ;-) You are correct that the
>RM no longer requires that the range be based on a power of two, but
>the rules for the attribute 'SIZE get mixed in here.  Since T'SIZE is
>in (integer) bits, it must be 4 or greater (see 13.3).  Any range that
>includes 1..10 is legal, including -5..10.  But T'BASE'SIZE must be at
>least 5, because of the rule about symmetric ranges.  So there are at
>least 31 possible values for an object of type T'BASE.  (Thirty-one?
>Yep, thirty-one.  This is due to the dispensation for ones-complement
>machines to allow for two zeros.)

"no longer"?  The rules are the same in Ada 83 and 95.  There is not,
and never was, any requirement for power-of-2 base ranges.

The rules for 'Size do *not* "get mixed in here".

Assuming the SP annex is supported, then T'Size=4, and T'Base'Size=5.
See 13.3(55).  But this has nothing whatsoever to do with the range of T
or T'Base.

Two zeros?  There is no dispensation -- there's only one zero for
integers in Ada.  If the machine is one's complement, and therefore has
two ways to represent zero, then the Ada compiler and/or hardware have
to make that fact invisible.

>   Since the anonymous type is unconstrained and contains all the
>legal values of an object of type T'BASE, that means that there must
>be at least 31 possible values,

No -- see above.

>... again distributed symmetrically around
>zero, but there can be more.  And since the attribute is defined for
>subtypes and objects, not types, it is possible for the size in bits
>of an anonymous type to be log2(100) for example.  So minus one
>hundred to ninety-nine would be a possible range, but minus ten to ten
>would not be.

No.  -10..10 is valid for T'Base'Range.

>    Does this say that you can't put objects of (sub)type T in one
>digit on a decimal machine?  No.  

A better answer is "Who cares?"

>...It says that objects of type T'BASE
>sometimes require more space than objects of type T.

True.

>...This has always
>been a known ramification in Ada 83.  (In Ada 83 it only came up for
>loop variables, in Ada 95 it can appear in lots of other places.)

True.

- Bob




      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     ` Matthew Heaney
1997-01-30  0:00     ` Robert Dewar
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 [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