CSCI 431: Structured Data Types

A Brief Review

Two components required to define a data type:

Data Types may be determined:

A language's data types may be:

A declaration explicitly associates an identifier with a type (and thus representation)

Benefits offered by data types:

Arrays

An array is an aggregate of homogeneous data elements in which an individual element is identified by its position

Design Issues:

Indexing is a mapping from indices to elements

What type(s) are allowed for defining array subscripts?

Binding-Time Classifications

Four categories, based on subscript binding and storage binding:

Static Arrays

Fixed Stack-based Arrays

Stack-based Arrays

  • Range and storage are dynamic, but fixed from then on for the variable's lifetime
  • Examples: Ada locals in a procedure or block
  • Advantage:
  • Disadvantage:

    Heap-based Arrays

    Number of Array Subscripts

    Array Initialization

    Array Operations

    Array Slices

    Implementation of Arrays

    Associative Arrays

    An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys

    Design Issues:

    Perl Associative Arrays

    Character Strings

    Design Issues:

    Are strings primitive or composite?

    Fixed Length or Variable Length

    operations: relational operators, assignment, length, substr, concatenation, (many others)

    String Implementation (Storage Representation)


    Records

    A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names

    Design Issues:

    Record Definition Syntax


    Record Field References

    Record Operations

    Comparing Records and Arrays

    Unions

    A union is a type whose variables are allowed to store different type values at different times during execution

    implementation of union

    Design Issues for unions:

    Union Examples

    Union Type-Checking Problems

    Ada Discriminated Unions

    Free Unions

    Evaluation of Unions

    Sets

    Set Examples

    Evaluation of Sets

    Set implementation:

    The ultimate in bad manners: Pointers

    C.A.R. Hoare (1973): "Their introduction into high-level languages may be a step backwards from which we may never recover."

    A pointer type is a type in which the range of values consists of memory addresses and a special value, nil (or null)

    Uses:

    Pointers vs. References

    Pointer Design Issues

    Fundamental Pointer Operations

    Problems with Pointers

    Dangling Pointers

    Memory Leaks

    Double Deallocation

    Aliasing

    Pointer Examples

    Evaluation of Pointers