* Conrolled types at library level only?
@ 1996-08-26 0:00 David Hunter
1996-08-26 0:00 ` James Squire
1996-08-28 0:00 ` Robert Dewar
0 siblings, 2 replies; 3+ messages in thread
From: David Hunter @ 1996-08-26 0:00 UTC (permalink / raw)
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?
--
David Hunter
Mary Washington College
Computer Science Department
hunter@mwc.edu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Conrolled types at library level only?
1996-08-26 0:00 Conrolled types at library level only? David Hunter
@ 1996-08-26 0:00 ` James Squire
1996-08-28 0:00 ` Robert Dewar
1 sibling, 0 replies; 3+ messages in thread
From: James Squire @ 1996-08-26 0:00 UTC (permalink / raw)
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"
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Conrolled types at library level only?
1996-08-26 0:00 Conrolled types at library level only? David Hunter
1996-08-26 0:00 ` James Squire
@ 1996-08-28 0:00 ` Robert Dewar
1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1996-08-28 0:00 UTC (permalink / raw)
iDavid Hunter asks
"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?"
When GNAT outputs a message like this, it is telling you that your
program is illegal, and why it is illegal, and it is absolutely right,
the source of your problem is that "controlled types can only be
defined at library level"!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1996-08-28 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-26 0:00 Conrolled types at library level only? David Hunter
1996-08-26 0:00 ` James Squire
1996-08-28 0:00 ` Robert Dewar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox