Ada Access Types¶
This document contains a loose number of notes about access types in Ada. This is a complex topic with quite some pitfalls
Implicit Dereference¶
This is a feature that was introduced in Ada 2012 and is described In this document
It allows to define reference types which can be passed around and used to access the underlying target.
Normally, when using an access type, you need to use the .all attribute to de-reference it [1] but
implicit de-reference allows you to use references without using .all.
1type LF_Ref (Element : not null access Real) is null record with
2 Implicit_Dereference => Element;
This defines an access type LF_Ref to access variables of type Real (just another name for a
Long_Float) which implicitly dereferences Element. Now, this is really a record type with
Element as its single member and discriminant and whenever you use a variable of this type to access
a Real value, it will automatically dereference and allows read/write access to its target.
1type AuxAngleClass is tagged record
2 xx : aliased Real := 0.0;
3 yy : aliased Real := 0.0;
4end record;
5
6AA : AuxAngleClass := (xx => 0.0, yy => 0.0);
7R : LF_Ref := Aux_Angle.xx;
This will give you an access type to AA.xx but you do not have to use .all in order to access the
target value. You can do something like R := 12.3; and
—