comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: limited/non-limited in Ada95
Date: 1997/10/21
Date: 1997-10-21T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680002110971905450001@news.ni.net> (raw)
In-Reply-To: 344ccece.1720086@SantaClara01.news.InterNex.Net


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
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  reply	other threads:[~1997-10-21  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-13  0:00 limited/non-limited in Ada95 Tom Moran
1997-10-16  0:00 ` Matthew Heaney
1997-10-17  0:00   ` Jon S Anthony
1997-10-18  0:00     ` Matthew Heaney
1997-10-21  0:00       ` Jon S Anthony
1997-10-21  0:00         ` Robert A Duff
1997-10-22  0:00           ` Robert Dewar
1997-10-22  0:00             ` Jon S Anthony
1997-10-22  0:00           ` Jon S Anthony
1997-10-23  0:00             ` Fergus Henderson
1997-10-23  0:00               ` Jon S Anthony
1997-10-24  0:00                 ` Geert Bosch
1997-10-23  0:00               ` Jon S Anthony
1997-10-21  0:00         ` Robert Dewar
1997-10-21  0:00           ` Jon S Anthony
1997-10-22  0:00             ` Robert Dewar
1997-10-22  0:00               ` Jon S Anthony
1997-10-18  0:00     ` Tom Moran
1997-10-18  0:00       ` Matthew Heaney
1997-10-19  0:00         ` Tom Moran
1997-10-19  0:00           ` Matthew Heaney
1997-10-21  0:00             ` Tom Moran
1997-10-21  0:00               ` Matthew Heaney [this message]
1997-10-21  0:00         ` Robert A Duff
1997-10-21  0:00   ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox