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: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Question about base types Date: 1997/01/30 Message-ID: #1/1 X-Deja-AN: 213213453 references: organization: New York University newsgroups: comp.lang.ada Date: 1997-01-30T00:00:00+00:00 List-Id: 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.