Ada Programming/Keywords/aliased


Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Description edit

If you come from C/C++ you are probably used to the fact that every element of an array, struct/record and other variables has an address. The C/C++ standards actually demand that. In Ada this is not true.

Ada is a self optimizing language — there is for example no register keyword like in C/C++. Ada compilers will use a register for storage automatically. Incidentally, most C/C++ compilers nowadays just ignore the register and allocate registers themselves, just like Ada does.

So if you want to take an access from any variable you need to tell the compiler that the variable needs to be in memory and may not reside inside a register. This is what the keyword aliased is for. Additionally it also serves as a hint to the reader of the program about the existence of pointers referencing the variable.

For variables edit

I : aliased Integer := 0;

For type declarations edit

For the elements of an array edit

Declaring an array as aliased will only ensure that the array as a whole has an address. It says nothing about the individual elements of the array — which may be packed in a way that more than one element has the same address. You need to declare the actual elements as aliased as well. You can read in Types/array how this is done. Here is just a short example:

 type Day_Of_Month is range 1 .. 31;
 type Day_Has_Appointment is array (Day_Of_Month) of aliased Boolean;

For the elements of a record edit

Just like arrays, declaring a record as aliased will only ensure that the record as a whole has an address. It says nothing about the individual elements of the record — which again may be packed and share addresses. Again you need to declare the actual elements as aliased as well. You can read in Types/record how this is done. Here is just a short example:

type Basic_Record is
   record
      A : aliased Integer;
   end record;

See also edit

Wikibook edit

Ada Reference Manual edit

Ada Quality and Style Guide edit


Ada Keywords
abort else new return
abs elsif not reverse
abstract (Ada 95) end null
accept entry select
access exception of separate
aliased (Ada 95) exit or some (Ada 2012)
all others subtype
and for out synchronized (Ada 2005)
array function overriding (Ada 2005)
at tagged (Ada 95)
generic package task
begin goto pragma terminate
body private then
if procedure type
case in protected (Ada 95)
constant interface (Ada 2005) until (Ada 95)
is raise use
declare range
delay limited record when
delta loop rem while
digits renames with
do mod requeue (Ada 95) xor