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=0.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,68c11ba628510a3a X-Google-Attributes: gid103376,public From: James Squire Subject: Re: Conrolled types at library level only? Date: 1996/08/26 Message-ID: <322266FD.D6B@mdc.com>#1/1 X-Deja-AN: 176690816 references: <32221600.69CD@interserf.net> content-type: text/plain; charset=us-ascii organization: McDonnell Douglas Aerospace mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.02 (Win16; I) Date: 1996-08-26T00:00:00+00:00 List-Id: 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"