Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Guidance on accessibility level rules

12 views
Skip to first unread message

Robert A Duff

unread,
Oct 5, 1995, 3:00:00 AM10/5/95
to
In article <44viml$1...@oznet03.ozemail.com.au>,
Andrew LESH <les...@ozemail.com.au> wrote:
>I think that accessibility level is similar to lexical level in a
>block structured language. What is the difference ?

Yes, that's right. Just remember that packages don't count as new
levels.

The simplest rule is: Always declare all your tagged types (including
type extensions), in library packages. You can nest them within any
number of nested packages (or child packages), but not within
procedures, tasks, or block_statements. This is not the actual rule in
the RM, but it's easy to understand, easy to follow, and will keep you
out of trouble. (I.e. this rule is more conservative than the real
rule.)

Note that tagged types normally need to be in package specs (or generic
package specs) anyway -- because otherwise, you can't declare new
dispatching subprograms for the type.

Packages don't count, because variables in a package don't "go away"
when you "exit" the package. But when you exit a subprogram, all of its
local variables go away, so a subprogram introduces another
accessibility level. That's why you were able to do things in a library
package, but not in a library subprogram.

Generics are a little bit more complicated. The simplest rule is: If
you want to declare a tagged type in a generic package, that's fine, but
make sure the generic package is not nested within any procedures,
tasks, or block_statements. The generic package can be a library unit,
or nested within other packages or generic packages. Also, declare the
tagged types in the package spec. (If you don't want it to be visible,
put it in the private part, but not in the body.) And finally,
instantiate the package in a place that is not nested within any
subprogram, task, or block_statement.

Does that help?

- Bob

0 new messages