An object declared by an object declaration is created by the elaboration of the object declaration and is denoted by a simple name or by some other form of name. In contrast, there are objects that are created by the eval- uation of allocators (see 4.8) and that have no simple name. Access to such an object is achieved by an access value returned by an allocator; the access value is said to designate the object.
access_type_definition ::= access subtype_indication
For each access type, there is a literal null which has a null access value designating no object at all. The null value of an access type is the default initial value of the type. Other values of an access type are obtained by evaluation of a special operation of the type called an allocator. Each such access value designates an object of the subtype defined by the subtype indication of the access type definition; this subtype is called the designated subtype; the base type of this subtype is called the designated type. The objects designated by the values of an access type form a collection implicitly associated with the type.
The elaboration of an access type definition consists of the elaboration of the subtype indication and creates an access type.
If an access object is constant, the constrained access value cannot be changed and always designates the same object. On the other hand, the value of the designated object need not remain the same (assignment to the designated object is allowed unless the designated type is limited).
The only forms of contraint that are allowed after the name of an access type in a subtype indication are index constraints and discriminant constraints. (See sections 3.6.1 and 3.7.2 for the rules applicable to these subtype indications.) An access value belongs to a corresponding subtype of an access type either if the access value is the null value or if the value of the designated object satisfies the constraint.
type FRAME is access MATRIX; -- see 3.6 type BUFFER_NAME is access BUFFER -- see 3.7.1
An access value delivered by an allocator can be assigned to several access objects. Hence it is possible for an object created by an allocator to be designated by more than one variable or constant of the access type. An access value can only designate an object created by an allocator; in particular, it cannot designate an object declared by an object declaration.
If the type of the objects designated by the access values is an array type or a type with discriminants, these objects are constrained with either the array bounds or the discriminant values supplied implicitly or explicity for the corresponding allocators (see 4.8).
Access values are called pointers of references in some other languages.
References: allocator, array type, assignment, belong to a subtype, constant, constraint, discriminant constraint, elaboration, index constraint, index specification, limited type, literal, name, object, object declaration, reserved word, satisfy, simple name, subcomponent, subtype, subtype indication, type, variable.
Rationale references: 6 Access Types
Style Guide references: 5.4.3 Dynamic Data, 5.9.2 Unchecked Deallocation, 6.1.3 Dynamic Tasks, 7.6.6 Unchecked Deallocation, 7.7.3 I/O on Access Types
There are no particular limitations on the designated type of an access type. In particular, the type of a component of the designated type can be another access type, or even the same access type. This permits mutually dependent and recursive access types. Their declarations require a prior incomplete (or private) type declaration for one or more types.
incomplete_type_declaration ::= type identifier [discriminant_part];
For each incomplete type declaration, there must be a corresponding declaration of a type with the same identifier. The corresponding declaration must be either a full type declaration or the declarations of a task type. In the rest of this section, explanations are given in terms of full type declarations; the same rules apply also to declarations of task types. If the incomplete type declaration occurs immediately within either a declarative part or the visible part of a package specification, then the full type declaration must occur later and immediately within this declarative part or visible part. If the incomplete type declaration occurs immediately within private part of a package, then the full type declaration must occur later and immediately within either the private part itself, or the declarative part of the corresponding package body.
A discriminant part must be given in the full type declaration if and only if one is given in the incomplete type declaration; if discriminant parts are given, then they must conform (see 6.3.1 for the conformance rules). Prior to the end of the full type declaration, the only allowed use of a name that denotes a type declared by an incomplete type declaration is as the type mark in the subtype indication of an access type definition; the only form of constraint allowed in this subtype indication is a discriminant constraint.
The elaboration of an incomplete type declaration creates a type. If the incomplete type declaration has a discriminant part, this elaboration includes that of the discriminant part: in such a case, the discriminant part of the full type declaration is not elaborated.
Example of a recursive type:
type CELL; -- incomplete type declaration type LINK is access CELL; type CELL is record VALUE : INTEGER; SUCC : LINK; PRED : LINK; end record; HEAD : LINK := new CELL'(O, null, null); NEXT : LINK := HEAD.SUCC;
Examples of mutually dependent access types:
type PERSON(SEX : GENDER); -- incomplete type declaration type CAR; -- incomplete type declaration type PERSON_NAME is access PERSON; type CAR_NAME is access CAR; type CAR is record NUMBER : INTEGER; OWNER :PERSON_NAME; end record; type PERSON(SEX : GENDER) is record NAME : STRING(1 .. 20); BIRTH : DATE; AGE : INTEGER range 0 .. 130; VEHICLE : CAR_NAME; case SEX is when M => WIFE : PERSON_NAME(SEX => F); when F => HUSBAND : PERSON_NAME(SEX => M); end case; end record; MY_CAR, YOUR_CAR, NEXT_CAR : CAR_NAME; -- implicitly initialized with null value
References: access type, access type definition, component, conform, constraint, declaraton, declarative item, designate, discriminant constraint, discriminant part, elaboration, identifier, name, subtype indication, type, type mark.
Style Guide references: 5.4.3 Dynamic Data
The basic operations of an access type include the operations involved in assignment, allocators for the access type, membership tests, qualification, explicit conversion, and the literal null. If the designated type is a type with discriminants, the basic operations include the selection of the corresponding discriminants; if the designated type is a record type, they include the selection of the corresponding components; if the designated type is an array type, they include the formation of indexed components and slices; if the designated type is a task type, they include selection of entries and entry families. Furthermore, the basic operations include the formation of a selected component with the reserved word all (see 4.1.3).
If the designated type is an array type, the basic operations include the attributes that have the attribute designators FIRST, LAST, RANGE, and LENGTH (likewise, the attribute designators of the N-th dimension). The prefix of each of these attributes must be a value of the access type. These attributes yield the corresponding characteristics of the designated object (see 3.6.2).
If the designated type is a task type, the basic operations include the attributes that have the attribute designators TERMINATED and CALLABLE (see 9.9). The prefix of each of these attributes must be a value of the access type. These attributes yield the corresponding characteristics of the designated task objects.
In addition, the attribute T'BASE (see 3.3.3) and the representation attributes T'SIZE and T'STORAGE_SIZE (see 13.7.2) are defined for an access type or subtype T; the attributes A'SIZE and A'ADDRESS are defined for an access object A (see 13.7.2).
Besides the basic operations, the operations of an access type include the predefined comparison for equality and inequality.
References: access type, allocator, array type, assignment, attribute, attribute designator, base type, basic operation, collection, constrained array subtype, conversion, designate, designated subtype, designated type, discriminant, indexed component, literal, membership test, and 4.5.2, object, operation, private type, qualified expression, record type, selected component, slice, subtype, task type, type.
Address any questions or comments to email@example.com.