next up previous contents
Next: Abstract Data Types Up: Syntax Previous: Named Record Definition and   Contents

Named Type Definition and Reference

As it turns out, we can define a name for any type, including arrays! For example, we can use the following type definitions for two array types:

const
  bigSize = 100;
  smallSize = 10;
type
  BigIntArray = array [0..bigSize-1] of integer;
  SmallIntArray = array [0..smallSize-1] of integer;

If we need two BigIntArrays and three SmallIntArrays, we can use the following variable definitions:

var
  bigA, bigB : BigIntArray;
  littleC, littleD, littleE : SmallIntArray;

Note that the type names can be used to define parameters and local variables as well as global variables. This helps both in terms of making a program more legible (due to the lack of cluttering array or record definitions) and easier to maintain (only need one change to the definition of a type name instead of changes to individual array or record variable definitions throughout the program).

In most other languages, you can associate a symbolic name with record types but not array types.


Tak Auyeung 2003-12-03