DATA


1. INTRODUCTION

All computer software works with data of some form. Literally the word data means - "that which is given". Any data item used in a program has a number of attributes:

  1. An Address.
  2. A Value which in turn has:
  3. A set of Operations that may be performed on it.
  4. A Name to tie the above together (also referred to as a label or identifier).

The nature of a these attributes is defined by the type of a data item.


1.1. Address


1.2. Value


1.3. Operations

The type of a data item also dictates the operations that can be performed on it. For example numeric data types can have the standard mathematical operations performed on them while string data types cannot.


1.4. Names

To do anything useful with a data item all the above must be tied together by giving the data item an identifying name (sometimes referred to as a label or an identifier). In Ada:


1.5 Summary

Data Items comprise: (1) a name, (2) an address and (3) a value.

DATA ITEM ATTRIBUTES

(notation after Baron 1977). It is important to distinguish between these. The type of a data item dictates:

Data items can be classified as being either global or local and/or either variables or constants. The nature of a data item is defined through a data declaration.


2. DATA DECLARATIONS, ASSIGNMENT AND INITIALISATION

A data declaration introduces a data item. In Ada this is achieved by associating the item (identified by a name) with a data type:

I_ITEM : INTEGER;

Here we have declared a data item I_ITEM which is of type INTEGER. Assignment is the process of associating a value with a data item. Usually achieved using an assignment operator. Ada example:

I_ITEM := 2;

Here we have assigned the value 2 to the data item I_ITEM. Initialisation is then the process of assigning an initial value to a data item on declaration. Examples in Ada:

I_ITEM : INTEGER := 2;

Here we have declared a data item I_ITEM which is of type INTEGER and takes an initial value of 2.

Here follows a short program to illustrate the different forms of data initialisation available in Ada:

with CS_IO;
use CS_IO;

procedure INIT_ADA is
        A_VALUE          : INTEGER := 1;
        B_VALUE, C_VALUE : INTEGER := 3;
        D_VALUE          : INTEGER := B_VALUE;
        E_VALUE          : INTEGER := A_VALUE + C_VALUE + 1;
begin
        PUT(A_VALUE);
        PUT(B_VALUE);
        NEW_LINE;
        PUT(C_VALUE);
        PUT(D_VALUE);
        NEW_LINE;
        PUT(E_VALUE);
        NEW_LINE;
end INIT_ADA;

Note that Ada supports multiple initialisation (e.g. C_VALUE, D_VALUE: integer:= 3;).


3. GLOBAL AND LOCAL DATA

Data items have associated with them:

  1. A life time - the period during the running of a program when they can be said to exist.
  2. A visibility - the parts of the program from where they can be accessed ("seen").

The nature of the life time and visibility of a data item is dictated by what are referred to as scoping rules. In this respect there are two types of data:

  1. Global data, which has a life time equivalent to an entire program and is visible from anywhere within that programme.
  2. Local data, whose life time and visibility is in some way limited.

It is a good idea to use local data items where ever possible. This stops the program from getting cluttered and difficult to read and prevents accidental changes to the values associated with such data items.


4. VARIABLES


5. CONSTANTS

It is sometimes desirable to define a data item whose value cannot be changed. Such data items are referred to as constants. In Ada they are indicated by incorporating the key word constant into the declaration:

I_ITEM : constant := 2;

Here we have declared a constant I_ITEM which has a value of 2. Note that the compiler will deduced that the data item is of type INTEGER. Conceptually we can think of a constant as a data item comprising only of a name and a value (i.e. no address):

CONSTANT DATA ITEM

However it should be appreciated that what we are doing here is telling the compiler to "flag" the data item as a constant (i.e. we are only instigating software protection). Theoretically we can still change the bit pattern representing the value if we can ascertain its address, i.e. find where it is stored.


6. ANONYMOUS DATA ITEMS

Often we use data items in a programme without giving them a name, such data items are referred to as anonymous data items. For example in the arithmetic expression:

I_ITEM + (5*6)

The (5*6) is an anonymous data item. The resulting data item produced by resolving this expression has a value (30) which is stored at some address, but has no label. The significance is that anonymous data items cannot be changed or used again in other parts of a program. Conceptually we can think of an anonymous data item as a data item without a name, consequently we cannot access its address (and hence the value stored at this address).

ANONYMOUS DATA ITEM

7. UNINITIALISED VARIABLES

It is possible to define a data item that is not initialised and does not have a value assigned to it later in the life of a program. Such a data item is referred to as an uninitialised variable. Of course the binary digits at the indicated address will have some setting (left over from previous executions of programs) and therefore the data item will have some arbitrary value associated with it. The presence of such data items indicates that "something is not quite righ" and thus compilers are usually designed to detect such items. Using Barron's notation we can conceive of an uninitialised data item as follows.

UNINITIALISED DATA ITEM



Created and maintained by Frans Coenen. Last updated 11 October 1999