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,34d47d048b177d0b X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: limited/non-limited in Ada95 Date: 1997/10/21 Message-ID: #1/1 X-Deja-AN: 284949847 References: <3442C2A3.3781@bix.com> <3449390f.142507@SantaClara01.news.InterNex.Net> <344a4329.812635@SantaClara01.news.InterNex.Net> <344ccece.1720086@SantaClara01.news.InterNex.Net> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-10-21T00:00:00+00:00 List-Id: In article <344ccece.1720086@SantaClara01.news.InterNex.Net>, tmoran@bix.com (Tom Moran) wrote: >>>Another problem is that once a tagged type is non-limited, no >>>extension can be, or have components that are,llimited. > >>Yes, that's true. But you could always add a discriminant of a named >>access type to the derived type, to point to objects that are limited. > Using a (named)access type instead of the limited object directly is >ugly, increases code size and complexity, is error prone, and >expensive (eg on Windows CE where they tell you to avoid memory >allocation/deallocation as much as possible) . Other than that, it's >just fine. :( No memory allocation is implied by this advice; in fact, just the opposite. type DT is access all LT; type NLT (D : DT) is tagged private; ... declare LO : aliased LT; NLO : NLT (LO'Unchecked_Access); begin So where is the "ugliness, increase in code size, and memory allocation"? No use of heap is necessary. True, this isn't as safe as an access discriminant, but if you're doing what you'd do with an access discriminant (ie location of the variable you're pointing to), then I don't think there's any great issue. Here's what one would do if you were to use an access discriminant: type LT (D : access T) is tagged limited private; declare O : aliased T; LO : LT (O'Access); begin Not much different, so I'm not clear what the objection is. The introduction of an "unnecessary" access type? It is true, however, that frequent conversions of access types will be required, when named access types are used instead of access parameters, which is an admitted pain. Mind you, there definately is one area where named access types must be used "unnecessarily," and that's when you want to use an access discriminant to designate a constant object (ie an in parameter of a subprogram). But the lack of "access constant" access parameters and discriminants is a known omission in the language, and will undoubtly be included in the next revision. For now, we have to live with using named access constant types (instead of the preferred access constant parameters and access constant discriminants) and Unchecked_Access. (Though the need for Unchecked_Access even with access discriminants is sometimes required.) -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271