Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

8.2. Scope of Declarations


For each form of declaration, the language rules define a certain portion of the program text called the scope of the declaration. The scope of a declaration is also called the scope of any entity declared by the declaration. Furthermore, if the declaration associates some notation with a declared entity, this portion of the text is also called the scope of this notation (either an identifier, a character literal, an operator symbol, or the notation for a basic operation). Within the scope of an entity, and only there, there are places where it is legal to use the associated notation in order to refer to the declared entity. These places are defined by the rules of visibility and overloading.

The scope of a declaration that occurs immediately within a declarative region extends from the beginning of the declaration to the end of the declarative region; this part of the scope of a declaration is called the immediate scope. Furthermore, for any of the declarations listed below, the scope of the declaration extends beyond the immediate scope:

  1. A declaration that occurs immediately within the visible part of a package declaration.

  2. An entry declaration.

  3. A component declaration.

  4. A discriminant specification.

  5. A parameter specification.

  6. A generic parameter declaration.
In each of these cases, the given declaration occurs immediately within some enclosing declaration, and the scope of the given declaration extends to the end of the scope of the enclosing declaration.

In the absence of a subprogram declaration, the subprogram specification given in the subprogram body or in the body stub acts as the declaration and rule (e) applies also in such a case.


The above scope rules apply to all forms of declaration defined by section 3.1; in particular, they apply also to implicit declarations. Rule (a) applies to a package declaration and thus not to the package specification of a generic declaration. For nested declarations, the rules (a) through

  1. apply at each level. For example, if a task unit is declared in the
visible part of a package, the scope of an entry of the task unit extends to the end of the scope of the task unit, that is, to the end of the scope of the enclosing package. The scope of a use clause is defined in section 8.4.

References: basic operation, body stub, character literal, component declaration, declaration, declarative region, discriminant specification, entry declaration, extends, generic declaration, generic parameter declaration, identifier, implicit declaration, occur immediately within, operator symbol, overloading, and 8.7, package declaration, package specification, parameter specification, record type, renaming declaration, subprogram body, subprogram declaration, task declaration, task unit, type declaration, use clause, visibility, visible part.

Rationale references: 11.2 Program Structure

Style Guide references: 4.1.6 Data Coupling, 4.2.3 Restricting Visibility, 7.6.6 Unchecked Deallocation


[Ada Information Clearinghouse]

Address any questions or comments to