From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d57302f2954365e1 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Question about base types Date: 1997/01/30 Message-ID: #1/1 X-Deja-AN: 213162645 references: <32EE1434.3BB4@elca-matrix.ch> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1997-01-30T00:00:00+00:00 List-Id: In article , Robert I. Eachus 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 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