7.2. Package Specifications and Declarations


The first list of declarative items of a package specification is called the visible part of the package. The optional list of declarative items after the reserved word private is called the private part of the package.

An entity declared in the private part of a package is not visible outside the package itself (a name denoting such an entity is only possible within the package). 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 clauses (see 4.1.3 and 8.4).

The elaboration of a package declaration consists of the elaboration of its basic declarative items in the given order.


The visible part of a package contains all the information that another program unit is able to know about the package. A package consisting of only a package specification (that is, without a package body) can be used to represent a group of common constants or variables, or a common pool of objects and types, as in the examples below.

Example of a package describing a group of common variables:

    package PLOTTING_DATA is
       PEN_UP : BOOLEAN;  

       X_MIN,    Y_MIN,
       X_MAX,    Y_MAX:   REAL;     --  see 3.5.7 

       X_VALUE : array (1 .. 500) of REAL;
       Y_VALUE : array (1 .. 500) of REAL;
    end PLOTTING_DATA;                                                             

Example of a package describing a common pool of objects and types:

    package WORK_DATA is
       type DAY is (MON, TUE, WED, THU, FRI, SAT, SUN); 
       type HOURS_SPENT is delta 0.25 range 0.0 .. 24.0;
       type TIME_TABLE  is array (DAY) of HOURS_SPENT; 

       NORMAL_HOURS : constant TIME_TABLE :=
                         (MON .. THU => 8.25, FRI => 7.0, SAT | SUN => 0.0);
    end WORK_DATA;   

References: basic declarative item, constant, declarative item, direct visibility, elaboration, expanded name, name, number declaration, object declaration, package, package declaration, package identifier, package specification, scope, simple name, type declaration, use clause, variable.