To create such variables, first create a type for it, called an access type.
Here's an example of an access type declaration, declaring that variables of type Node_Access can access (reference) objects of type Node:
type Node_Access is access Node;
Here is the BNF for creating an access type to an object:
access_object_type_declaration ::= "type" new_type_name "is" "access" ["all"] type_name ";"
Variables of access type can either refer to an object or be null. You can make an access variable null by assigning it the value of the keyword "null", and you can check if it's null by comparing the variable (using "=" or "/=") to "null".
The ability to "point" at other values is useful and efficient, but it can also be dangerous. It's easy to do the wrong thing with pointers and cause surprising results. Ada tries to limit the damage that you can do while maintaining efficiency. Ada does this through the following rules:
The Ada compiler will optimize these checks and initializations away if it can determine that they're unnecessary. You can also turn off these checks for a given subprogram if you know that that particular subprogram is totally correct.
Now that we know how to declare access types, let's see how we can use them.
There is no quiz question for this section.
You may go to the next section.
Go back to the previous section
Go up to the outline of lesson 12
David A. Wheeler (wheeler@ida.org)