Contents Index Search Previous Next
7.1 Package Specifications and Declarations
A package is generally provided in two parts:
a package_specification and a package_body.
Every package has a package_specification,
but not all packages have a package_body.
package defining_program_unit_name is
If an identifier
appears at the end of a package_specification,
then this sequence of lexical elements shall repeat the defining_program_unit_name.
a completion (a body) if it contains any declarative_item
that requires a completion, but whose completion is not in its package_specification
The first list of declarative_item
of a package_specification
package other than a generic formal package is called the visible
of the package.
The optional list of declarative_item
after the reserved word private
(of any package_specification
is called the private part
of the package. If the reserved word
does not appear, the package has an implicit empty private
An entity declared in the private part of a package
is visible only within the declarative region of the package itself (including
any child units -- see 10.1.1
). In contrast,
expanded names denoting entities declared in the visible part can be
used even outside the package; furthermore, direct visibility of such
entities can be achieved by means of use_clause
The elaboration of a package_declaration
consists of the elaboration of its basic_declarative_item
in the given order.
1 The visible part of a
package contains all the information that another program unit is able
to know about the package.
2 If a declaration occurs
immediately within the specification of a package, and the declaration
has a corresponding completion that is a body, then that body has to
occur immediately within the body of the package.
Example of a
package Rational_Numbers is
type Rational is
Numerator : Integer;
Denominator : Positive;
function "="(X,Y : Rational) return Boolean;
function "/" (X,Y : Integer) return Rational; -- to construct a rational number
function "+" (X,Y : Rational) return Rational;
function "-" (X,Y : Rational) return Rational;
function "*" (X,Y : Rational) return Rational;
function "/" (X,Y : Rational) return Rational;
There are also many examples of package declarations
in the predefined language environment (see Annex
Contents Index Search Previous Next Legal