comp.lang.ada
 help / color / mirror / Atom feed
From: James Squire <jsquire@mdc.com>
Subject: Re: Conrolled types at library level only?
Date: 1996/08/26
Date: 1996-08-26T00:00:00+00:00	[thread overview]
Message-ID: <322266FD.D6B@mdc.com> (raw)
In-Reply-To: 32221600.69CD@interserf.net


David Hunter wrote:
> 
> I've got a generic package that defines a controlled type.
> When I try to instantiate the package in a procedure,
> GNAT (3.04a) tells me that conrolled types can only be
> defined at library level.  Sure enough, I can instantiate
> the generic in a package but not in a procedure.  Is
> this rule part of the Ada95 definition or a particular
> weakness of GNAT?

OK, I'm gonna take a crack at this - without a net even.  You should 
check the Ada 95 Rationale for a more trustworthy explanation.

It's part of the Ada 95 definition (it's a feature, not a bug ;-) )

Controlled types are really just tagged types derived from 
Ada.Finalization.Controlled, which is defined at the library level.  In 
this case it is abstract, which makes this not a perfect example as we 
will soon see.  At any rate, you are trying to instantiate a package 
which will derive a type from Controlled, at a deeper than library level. 
 Suppose there is another type also derived from Controlled, only AT the 
library level, and suppose, at a higher level than the procedure you 
mentioned, there is a dispatching call, which could conceivably be asked 
to operate on an object of the type defined in the generic package (it's 
slightly tricky, but it can be done via globals).  At the library level, 
you would be trying to call a procedure that is not visible in the 
current scope, because it's scope is deeper.

They wanted to prevent you from making that mistake, so they said that 
derived tagged types must be derived at the same level as the parent 
type.  Since Controlled is the parent here, and since it is always 
defined at the library level since it is predefined for you, therefore, 
all controlled types must be declared at the library level.

How'd I do, all you gurus?
-- 
James Squire                             mailto:jsquire@mdc.com
MDA Avionics Tools & Processes
McDonnell Douglas Aerospace              http://www.mdc.com/
Opinions expressed here are my own and NOT my company's
"I will tell you a great secret, Captain.  Perhaps the greatest of all
 time. The molecules of your body are the same molecules that make up
 this station, and the nebula outside, that burn inside the stars
 themselves. We are starstuff, we are the universe, made manifest, trying
 to figure itself out. As we have both learned, sometimes the universe
 requires a change of perspective." 
        -- Delenn (to Sheridan), "A Distant Star"




  reply	other threads:[~1996-08-26  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-26  0:00 Conrolled types at library level only? David Hunter
1996-08-26  0:00 ` James Squire [this message]
1996-08-28  0:00 ` Robert Dewar
replies disabled

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