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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cd703a96ca51de6e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Thu, 08 Dec 2005 20:53:28 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <1134055303.758950.308680@o13g2000cwo.googlegroups.com> <1134065313.469475.267400@g47g2000cwa.googlegroups.com> <1134072443.635504.296550@g44g2000cwa.googlegroups.com> Subject: Re: 'Base Date: Thu, 8 Dec 2005 20:57:49 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4952.2800 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4952.2800 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-txY+LTLZIB17fFSNaI1xQWt3V9j34ODrqU1vD7c3WJpthSCRu2UOTMobvOjTzcZleHIVTFY+tFkV2Mr!cHOfKd8XLTZtkV5QUML7q1MzNvRWwGmmjt9bxhDm1V3I8TVOKil2M8jPyNExZvHPmTJWly4Ru+KK X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:6785 Date: 2005-12-08T20:57:49-06:00 List-Id: "Matthew Heaney" wrote in message news:1134072443.635504.296550@g44g2000cwa.googlegroups.com... > > Jeffrey R. Carter wrote: > > > > I'm surprised ObjectAda uses 32 bits for this. GNAT 3.4.2 uses 8 bits (-128 .. 127). > > Exactly my point. If you assume that you have more range than the RM > promises, then you're only asking for trouble. Not quite true. The range is always going to correspond to the representation; so unless you have to worry about non-binary machines, you can assume the next higher power of 2 minus 1; in this case 63. Of course, usually this isn't particularly relevant - the extra values are a small percentage of the total. Moreover, if you only want to worry about typical machines, then the values are only going to be some multiple of 8-bits, so 'Base'Last can pretty much be assumed to be the smallest value of 2**(8*N-1)-1 without trouble. But of course the whole point of these attributes is so you don't have to assume at all. BTW, 'Base works on any scalar type, and the rules for floats and fixed point types are somewhat different than described in the messages here. And a quick answer for the OP: using 'Base is usually only needed in various tricks. Here's one. Imagine you want a type that can hold at least 0 .. 1000, but you don't care about the exact bounds and want the most efficient type possible. You can declare: type Restricted_Type is range 0 .. 1000; type Big_Enough_Type is range Restricted_Type'Base'First .. Restricted_Type'Base'Last; and Big_Enough_Type will be some full-range type appropriate for the machine (probably 16-bits or 32-bits). Matt gave another example. Suppose you have a generic: generic type G_Int is range <>; package Gen is ... and you need a counter of type G_Int that starts at zero and goes to the upper bound of G_Int. Sloppy programmers would just use G_Int for such an counter, but that would fail if the range of G_Int didn't include zero. Slightly less sloppy programmers would declare the counter as having the type G_Int'Base, but that isn't going to have the overflow check. The best solution is to declare the counter as: Counter : G_Int'Base range 0 .. G_Int'Last; which ensures that 0 is included, and the right range is used. Note that this could cover a larger range than the original type. Randy.