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,141791b1b1db9b37 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Integer-Types References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <6KC8d.3566$UP1.3327@newsread1.news.pas.earthlink.net> Date: Tue, 05 Oct 2004 19:37:38 GMT NNTP-Posting-Host: 63.184.105.143 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1097005058 63.184.105.143 (Tue, 05 Oct 2004 12:37:38 PDT) NNTP-Posting-Date: Tue, 05 Oct 2004 12:37:38 PDT Xref: g2news1.google.com comp.lang.ada:4747 Date: 2004-10-05T19:37:38+00:00 List-Id: Rick Santa-Cruz wrote: > So this means the main difference is, that without the "new" the > compiler will choose the Base-Type (for example a short-int) and in > the second case I explicitly decide which is the base-type. Is this > correct? That's right. You can also leave off the range information, in which case the new type is just like the parent type, but is a different type with a different name. New, in a type declaration, declares a derived type. A derived type has the same representation as the parent (unless that is changed with representation clauses) and inherits all the primitive operations of the parent. Conversions between the two types are also defined. Sometimes this is useful. Suppose you have a memory location that maps to a hardware output register. The register can have only a few valid values. Then you can write: type Sensor_State is (One, Two, Three, Four); Suppose the 4 values are represented by 1, 2, 4, 8, respectively. You can hide this external representation from your application using a derived type. Define an operation to read the sensor and return a Sensor_State. The rest of the application doesn't need to know that the register uses a different encoding: function Get return Sensor_State is type Hardware_Sensor_State is new Sensor_State; for Hardware_Sensor_State'Size use Hardware_Register_Size; for Hardware_Sensor_State use (One => 2#0001#, Two => 2#0010#, Three => 2#0100#, Four => 2#1000#); Register : Hardware_Sensor_State; for Register'Address use Hardware_Sensor_Address; pragma Import (Ada, Register); pragma Volatile (Register); begin -- Get return Sensor_State (Register); end Get; This is called a change of representation. > Is there somewhere a summing-up in which contexts I can use the > keyword "new"? Not that I know of. ARM Annex P contains a syntax summary. > I know some: > 1.) For declaring a new type For declaring a derived type. > 2.) For deriving from tagged-types This is also a derived type. It's called a type extension, because the new type extends the parent. > 3.) For using with pointers... that means for creating a > pointer-object. This is an allocator. It doesn't create a pointer object. It allocates an object of the designated type and returns an access value designating that object. > 4.) In the context of the instantiation of generics Annex P shows derived type definition (including formal derived type definitions) allocator private extension definition generic instantiation (including formal package definitions) -- Jeff Carter "We burst our pimples at you." Monty Python & the Holy Grail 16