University of California, Santa Cruz

Prof. Paulo Franca - Spring 2000

Introduction

Syllabus

Guidelines for labs

Lab sections

Take quiz & check grades

Abstract Data Type implementations in C

a structure of data inaccessible to the user except through a predefined set of functions...

What do we need?

  1. user cannot access the data in the ADT directly;
  2. user cannot modify the functions of the ADT;
  3. user needs to know the interface so he or she can write programs using the ADT
  4. user program needs to refer and link to the ADT
  5. a given program may use more than one object of the same ADT.
  6. Most likely, user will only have the object code of the ADT

How can we do that?

bulletWrite the data structures and the functions in a separate file (which may even be supplied in object form). That takes care of 1 and 2.
bulletWrite a header file with function prototypes and declarations for whatever pieces of data the user is allowed to see and make references. That takes care of 3 and part of 4.
bulletUse a handle (a pointer to each object of the ADT). The user declares the handle to be a pointer to the desired ADT. The value of the pointer should be set by a constructor (initialization) function of the ADT. User will keep that particular pointer to refer to that particular object. If more than one object are needed, just use other handles. That takes care of 5.
bulletSince  you need to put together several program files, you need to instruct the linker by means of a make file. This takes care of 4.