Prev | Up | ____ | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


3.10.2 Operations of Access Types

(1)
The attribute Access is used to create access values designating aliased objects and non-intrinsic subprograms. The ``accessibility'' rules prevent dangling references (in the absence of uses of certain unchecked features -- see Section 13).
Name Resolution Rules
(2)
For an attribute_reference with attribute_designator Access (or Unchecked_Access -- see 13.10), the expected type shall be a single access type; the prefix of such an attribute_reference is never interpreted as an implicit_dereference. If the expected type is an access-to-subprogram type, then the expected profile of the prefix is the designated profile of the access type.
Static Semantics
(3)
The accessibility rules, which prevent dangling references, are written in terms of accessibility levels, which reflect the run-time nesting of masters. As explained in 7.6.1, a master is the execution of a task_body, a block_statement, a subprogram_body, an entry_body, or an accept_statement. An accessibility level is deeper than another if it is more deeply nested at run time. For example, an object declared local to a called subprogram has a deeper accessibility level than an object declared local to the calling subprogram. The accessibility rules for access types require that the accessibility level of an object designated by an access value be no deeper than that of the access type. This ensures that the object will live at least as long as the access type, which in turn ensures that the access value cannot later designate an object that no longer exists. The Unchecked_Access attribute may be used to circumvent the accessibility rules.
(4)
A given accessibility level is said to be statically deeper than another if the given level is known at compile time (as defined below) to be deeper than the other for all possible executions. In most cases, accessibility is enforced at compile time by Legality Rules. Run-time accessibility checks are also used, since the Legality Rules do not cover certain cases involving access parameters and generic packages.
(5)
Each master, and each entity and view created by it, has an accessibility level:
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
One accessibility level is defined to be statically deeper than another in the following cases:
(18)
(19)
(20)
(21)
(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.
(23)
The following attribute is defined for a prefix X that denotes an aliased view of an object:
(24)
X'Access
(25)
(26)
(27)
(28)
(29)
(30)
(31)
The following attribute is defined for a prefix P that denotes a subprogram:
(32)
P'Access

(33)
(34)
(35)
(36)
(37)
(38)
(39)
Examples
(40)
Example of use of the Access attribute:
(41)
       Martha : Person_Name := new Person(F);       -- see 3.10.1
       Cars   : array (1..2) of aliased Car;
          ...
       Martha.Vehicle := Cars(1)'Access;
       George.Vehicle := Cars(2)'Access;

Prev | Up | ____ | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12