13.10. Unchecked Programming

[PREVIOUS][UP]

The predefined generic library subprograms UNCHECKED_DEALLOCATION and UNCHECKED_CONVERSION are used for unchecked storage deallocation and for unchecked type conversions.

      generic
         type OBJECT is limited private;
         type NAME   is access  OBJECT;
      procedure UNCHECKED_DEALLOCATION(X: in out NAME);

      generic
         type SOURCE is limited private;
         type TARGET is limited private;
      function UNCHECKED_CONVERSION(S : SOURCE) return TARGET;

References: generic subprogram, library unit, type.

Sub-topics:

13.10.1. Unchecked Storage Deallocation

[UP][NEXT]

Unchecked storage deallocation of an object designated by a value of an access type is achieved by a call of a procedure that is obtained by instantiation of the generic procedure UNCHECKED_DEALLOCATION. For example:

      procedure FREE is new UNCHECKED_DEALLOCATION(object_type_name,
             access_type_name);

Such a FREE procedure has the following effect:

  1. after executing FREE(X), the value of X is null;

  2. FREE(X), when X is already equal to null, has no effect;

  3. FREE(X), when X is not equal to null, is an indication that the object designated by X is no longer required, and that the storage it occupies is to be reclaimed.

If X and Y designate the same object, then accessing this object through Y is erroneous if this access is performed (or attempted) after the call FREE(X); the efeect of each such access is not defined by the language.

Notes:

It is a consequence of the visibility rules that the generic procedure UNCHECKED_DEALLOCATION is not visible in a compilation unit unless this generic procedure is mentioned by a with clause that applies to the compilation unit.

If X designates a task object, the call FREE(X); has no effect on the task designated by the value of this task object. The same holds for any subcomponent of the object designated by X, if this subcomponent is a task object.

References: access type, apply, compilation unit, designate, and 9.1, erroneous, generic instantiation, generic procedure, generic unit, library unit, null access value, object, procedure, procedure call, subcomponent, task, task object, visibility, with clause.

13.10.2. Unchecked Type Conversions

[PREVIOUS][UP]

An unchecked type conversion can be achieved by a call of a function that is obtained by instantiation of the generic function UNCHECKED_CONVERSION.

The effect of an unchecked conversion is to return the (uninterpreted) parameter value as a value of the target type, that is, the bit pattern defining the source value is returned unchanged as the bit pattern defining a value of the target type. An implementation may place restrictions on unchecked conversions, for example, restrictions dependeing on the respective sizes of objects of the source and target type. Such restrictions must be documented in appendix F.

Whenever unchecked conversions are used, it is the programmer's responsibility to ensure that these conversions maintain the properties that are guaranteed by the language for objects of the target type. Programs that violate these properties by means of unchecked conversions are erroneous.

Note:

It is a consequence of the visibility rules that the generic function UNCHECKED_CONVERSION is not visible in a compilation unit unless this generic function is mentioned by a with clause that applies to the compilation unit.

References: apply, compilation unit, erroneous, generic function, instantiation, parameter of a subprogram, type, with clause.

[PREVIOUS][UP][NEXT]


[INDEX][CONTENTS]