comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Library Level Question
Date: 1999/02/15
Date: 1999-02-15T00:00:00+00:00	[thread overview]
Message-ID: <m3lnhztu9w.fsf@mheaney.ni.net> (raw)
In-Reply-To: 36c853cb.0@news.pacifier.com

"Steve Doiel" <nospam_steved@pacifier.com> writes:

> What exactly is meant by Library Level

I think of library level as the most outer scope of a system.

Think of a real library.  All the books in the library are at "library
level."  But if you open one of the books, and look at a diagram, then
the diagram is _not_ at library level, because it's _inside_ the book.

But the book itself is "inside" the library.  All the things we think of
as being inside the library are at library level (say, the things listed
in the card catalog).

In contrast, a diagram is "more nested," because it's inside the book,
not inside the library (and the diagram would not be in the library's
card catalog).


> Section 13.10.2 of the LRM gives the following description:
> 
>   (22)
>   The accessibility level of all library units is called the library level;
> a library-level declaration or entity is one whose accessibility level is
> the library level.
>
> Does this mean unit specifications? Implementations? Either?
> I'm obviously not a language lawyer, but am often able to figure things out
> from the LRM.  this has been an exception.

This just means that when you have a package, not declared in anything
else, as in

package Book is
  ...
end Book;

that it is at library level.  Just like our book.

But if we have a package inside another, like this:

package Book is

  package Diagram is 

  ...
  end Diagram;

...
end Book;


then the inner package is _not_ at library level.  The diagram is in the
book, not the library.

 
> My observation has been that when I try to take the address ('access) of a
> function or procedure that is defined within my main procedure, I get a
> message about the wrong library level.  But if I take the address of a
> function or procedure defined inside a package spec or body, the compiler is
> happy.


Because inside a procedure, you're not at library level, you're inside
something.  Stretching our analogy a bit, it's like trying to give a
reference to a diagram, without having to also refer to the book, and
that's illegal.

You have a couple of choices:

1) Declare the subprogram you want to call via a pointer inside a
   package at library level:

package Book is

   procedure Diagram;

end;

Now you can safely point to subprogram via a pointer.


2) If you're using GNAT, then you can go outside the Official Language
   by using 'Unrestricted_Access.  You are then allowed to point to your
   local subprogram, without any complaints from the compiler.


This "feature" of the language has been debated many times here on
c.l.a.  Go to DejaNews and search for "downward closures" to get more
info.








  reply	other threads:[~1999-02-15  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-15  0:00 Library Level Question Steve Doiel
1999-02-15  0:00 ` Matthew Heaney [this message]
1999-02-15  0:00   ` Steve Doiel
1999-02-15  0:00     ` kirk
1999-02-16  0:00       ` Steve Doiel
1999-02-23  0:00         ` Tucker Taft
1999-03-01  0:00   ` Robert A Duff
1999-03-08  0:00     ` Matthew Heaney
1999-02-15  0:00 ` David C. Hoos, Sr.
replies disabled

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